src/lib/update/prepare.c

Go to the documentation of this file.
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  *  prepare.c: Perform prelimiary updates of sectors
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare, 1986
00032  *     Thomas Ruschak, 1992
00033  *     Steve McClure, 1997
00034  */
00035 
00036 #include <config.h>
00037 
00038 #include "budg.h"
00039 #include "item.h"
00040 #include "land.h"
00041 #include "path.h"
00042 #include "player.h"
00043 #include "ship.h"
00044 #include "update.h"
00045 
00046 void
00047 prepare_sects(int etu, struct bp *bp)
00048 {
00049     struct sctstr *sp;
00050     struct natstr *np;
00051     int n, civ_tax, uw_tax, mil_pay;
00052 
00053     memset(levels, 0, sizeof(levels));
00054 
00055 /* Process all the fallout. */
00056     if (opt_FALLOUT) {
00057         if (!player->simulation) {
00058             /* First, we determine which sectors to process fallout in */
00059             for (n = 0; NULL != (sp = getsectid(n)); n++)
00060                 sp->sct_updated = sp->sct_fallout != 0;
00061             /* Next, we process the fallout there */
00062             for (n = 0; NULL != (sp = getsectid(n)); n++)
00063                 if (sp->sct_updated)
00064                     do_fallout(sp, etu);
00065             /* Next, we spread the fallout */
00066             for (n = 0; NULL != (sp = getsectid(n)); n++)
00067                 if (sp->sct_updated)
00068                     spread_fallout(sp, etu);
00069             /* Next, we decay the fallout */
00070             for (n = 0; NULL != (sp = getsectid(n)); n++)
00071                 if (sp->sct_fallout)
00072                     decay_fallout(sp, etu);
00073         }
00074     }
00075     for (n = 0; NULL != (sp = getsectid(n)); n++) {
00076         sp->sct_updated = 0;
00077 
00078         if (sp->sct_type == SCT_WATER)
00079             continue;
00080         bp_set_from_sect(bp, sp);
00081         np = getnatp(sp->sct_own);
00082 
00083 #ifdef DEBUG
00084         if (np->nat_stat == STAT_SANCT)
00085             logerror("Prepare.c: country in sanctuary skipped production");
00086 #endif /* DEBUG */
00087 
00088         if (np->nat_stat != STAT_SANCT) {
00089             guerrilla(sp);
00090             do_plague(sp, np, etu);
00091             tax(sp, np, etu, &pops[sp->sct_own], &civ_tax, &uw_tax,
00092                 &mil_pay);
00093             np->nat_money += civ_tax + uw_tax + mil_pay;
00094             if (sp->sct_type == SCT_BANK)
00095                 np->nat_money += bank_income(sp, etu);
00096         }
00097     }
00098     for (n = 0; NULL != (np = getnatp(n)); n++) {
00099         np->nat_money += upd_slmilcosts(np->nat_cnum, etu);
00100     }
00101 }
00102 
00103 void
00104 tax(struct sctstr *sp, struct natstr *np, int etu, long *pop, int *civ_tax,
00105     int *uw_tax, int *mil_pay)
00106 {
00107     *civ_tax = 0;
00108     *uw_tax = 0;
00109     *mil_pay = 0;
00110 
00111     if (!player->simulation)
00112         populace(np, sp, etu);
00113     *civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
00114                      etu * money_civ / 100);
00115     /*
00116      * captured civs only pay 1/4 taxes
00117      */
00118     if (sp->sct_own != sp->sct_oldown)
00119         *civ_tax = *civ_tax / 4;
00120     *uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
00121                     etu * money_uw / 100);
00122     *mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
00123 
00124     /*
00125      * only non-captured civs add to census for nation
00126      */
00127     if (sp->sct_oldown == sp->sct_own)
00128         *pop += sp->sct_item[I_CIVIL];
00129 }
00130 
00131 int
00132 upd_slmilcosts(natid n, int etu)
00133 {
00134     struct shpstr *sp;
00135     struct lndstr *lp;
00136     int mil = 0;
00137     int totalmil = 0;
00138     int mil_pay = 0;
00139     int i;
00140 
00141     for (i = 0; NULL != (sp = getshipp(i)); i++) {
00142         if (!sp->shp_own || sp->shp_own != n)
00143             continue;
00144         if ((mil = sp->shp_item[I_MILIT]) > 0)
00145             totalmil += mil;
00146     }
00147     for (i = 0; NULL != (lp = getlandp(i)); i++) {
00148         if (!lp->lnd_own || lp->lnd_own != n)
00149             continue;
00150         if ((mil = lp->lnd_item[I_MILIT]) > 0)
00151             totalmil += mil;
00152     }
00153     mil_pay = totalmil * etu * money_mil;
00154     return mil_pay;
00155 }
00156 
00157 int
00158 bank_income(struct sctstr *sp, int etu)
00159 {
00160     return (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
00161 }

Generated on Fri Mar 28 11:01:16 2008 for empserver by  doxygen 1.5.2