00001 /* 00002 * Empire - A multi-player, client/server Internet based war game. 00003 * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak, 00004 * Ken Stevens, Steve McClure 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 * --- 00021 * 00022 * See files README, COPYING and CREDITS in the root of the source 00023 * tree for related information and legal notices. It is expected 00024 * that future projects/authors will amend these files as needed. 00025 * 00026 * --- 00027 * 00028 * btu.c: Dealing with BTUs 00029 * 00030 * Known contributors to this file: 00031 * Markus Armbruster, 2007 00032 */ 00033 00034 #include <config.h> 00035 00036 #include "file.h" 00037 #include "nat.h" 00038 #include "optlist.h" 00039 #include "prototypes.h" 00040 #include "sect.h" 00041 00042 /* 00043 * Return BTUs produced by CAP in ETU ETUs. 00044 */ 00045 static int 00046 accrued_btus(struct sctstr *cap, int etu) 00047 { 00048 double eff, civ; 00049 00050 switch (cap->sct_type) { 00051 case SCT_CAPIT: 00052 case SCT_SANCT: 00053 eff = cap->sct_effic; 00054 break; 00055 case SCT_MOUNT: 00056 eff = 0; 00057 break; 00058 default: 00059 return 0; 00060 } 00061 00062 eff *= cap->sct_work / 100.0; 00063 if (eff < 0.5) 00064 eff = 0.5; 00065 00066 civ = cap->sct_item[I_CIVIL]; 00067 if (civ > 999) 00068 civ = 999; 00069 00070 return roundavg(etu * civ * eff * btu_build_rate); 00071 } 00072 00073 /* 00074 * Grant nation NP the BTUs produced by its capital in ETU ETUs. 00075 * Return whether it has a capital. 00076 */ 00077 int 00078 grant_btus(struct natstr *np, int etu) 00079 { 00080 int has_cap, delta; 00081 struct sctstr sect; 00082 00083 getsect(np->nat_xcap, np->nat_ycap, §); 00084 has_cap = np->nat_stat >= STAT_ACTIVE && !influx(np); 00085 00086 if (has_cap) { 00087 delta = accrued_btus(§, etu); 00088 if (delta + np->nat_btu > max_btus) 00089 np->nat_btu = max_btus; 00090 else 00091 np->nat_btu += delta; 00092 } 00093 if (np->nat_stat == STAT_VIS || np->nat_stat == STAT_GOD) 00094 np->nat_btu = max_btus; 00095 00096 return has_cap; 00097 }
1.5.2