src/lib/update/main.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  *  main.c: World update main function
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare, 1994
00032  *     Steve McClure, 1996
00033  *     Doug Hay, 1998
00034  *     Markus Armbruster, 2006-2007
00035  */
00036 
00037 #include <config.h>
00038 
00039 #include "budg.h"
00040 #include "empthread.h"
00041 #include "game.h"
00042 #include "journal.h"
00043 #include "player.h"
00044 #include "server.h"
00045 #include "update.h"
00046 
00047 long money[MAXNOC];
00048 long pops[MAXNOC];
00049 long sea_money[MAXNOC];
00050 long lnd_money[MAXNOC];
00051 long air_money[MAXNOC];
00052 long tpops[MAXNOC];
00053 
00054 void
00055 update_main(void)
00056 {
00057     int etu = etu_per_update;
00058     int n;
00059     int x;
00060     struct bp *bp;
00061     int cn, cn2, rel;
00062     struct natstr *cnp;
00063     struct natstr *np;
00064 
00065     logerror("production update (%d etus)", etu);
00066     game_record_update(time(NULL));
00067     journal_update(etu);
00068 
00069     /* First, make sure all mobility is updated correctly. */
00070     if (opt_MOB_ACCESS) {
00071         mob_ship();
00072         mob_sect();
00073         mob_plane();
00074         mob_land();
00075     }
00076 
00077     if (opt_AUTO_POWER)
00078         update_power();
00079 
00080     /*
00081      * set up all the variables which get used in the
00082      * sector production routine (for producing education,
00083      * happiness, and printing out the state of the nation)
00084      */
00085     memset(pops, 0, sizeof(pops));
00086     memset(air_money, 0, sizeof(air_money));
00087     memset(sea_money, 0, sizeof(sea_money));
00088     memset(lnd_money, 0, sizeof(lnd_money));
00089     bp = bp_alloc();
00090     for (n = 0; n < MAXNOC; n++) {
00091         money[n] = 0;
00092         if (!(np = getnatp(n)))
00093             continue;
00094         money[n] = np->nat_money;
00095         tpops[n] = count_pop(n);
00096     }
00097 
00098     logerror("preparing sectors...");
00099     prepare_sects(etu, bp);
00100     logerror("done preparing sectors.");
00101     logerror("producing for countries...");
00102     for (x = 0; x < MAXNOC; x++) {
00103         long p_sect[SCT_TYPE_MAX+2][2];
00104 
00105         memset(p_sect, 0, sizeof(p_sect));
00106         if (!(np = getnatp(x)))
00107             continue;
00108         if (np->nat_stat == STAT_SANCT) {
00109 #ifdef DEBUG
00110             logerror("Country %i is in sanctuary and did not update", x);
00111 #endif
00112             continue;
00113         }
00114         np->nat_money += (int)(np->nat_reserve * money_res * etu);
00115 
00116         /* maintain units */
00117         prod_ship(etu, x, bp, 0);
00118         prod_plane(etu, x, bp, 0);
00119         prod_land(etu, x, bp, 0);
00120 
00121         /* produce all sects */
00122         produce_sect(x, etu, bp, p_sect);
00123 
00124         /* build units */
00125         prod_ship(etu, x, bp, 1);
00126         prod_plane(etu, x, bp, 1);
00127         prod_land(etu, x, bp, 1);
00128     }
00129     logerror("done producing for countries.");
00130 
00131     finish_sects(etu);
00132     prod_nat(etu);
00133     age_levels(etu);
00134     free(bp);
00135     /*flushwu(); */
00136     if (opt_SLOW_WAR) {
00137         /* Update war declarations */
00138         /* MOBILIZATION->SITZKRIEG->AT_WAR */
00139         for (cn = 1; cn < MAXNOC; cn++) {
00140             if ((cnp = getnatp(cn)) == 0)
00141                 break;
00142             for (cn2 = 1; cn2 < MAXNOC; cn2++) {
00143                 if (cn2 == cn)
00144                     continue;
00145                 rel = getrel(cnp, cn2);
00146                 if (rel == MOBILIZATION) {
00147                     rel = SITZKRIEG;
00148                     setrel(cn, cn2, rel);
00149                 } else if (rel == SITZKRIEG) {
00150                     rel = AT_WAR;
00151                     setrel(cn, cn2, rel);
00152                 }
00153             }
00154         }
00155     }
00156     /* Only update mobility for non-MOB_ACCESS here, since it doesn't
00157        get done for MOB_ACCESS anyway during the update */
00158     if (!opt_MOB_ACCESS) {
00159         mob_ship();
00160         mob_sect();
00161         mob_plane();
00162         mob_land();
00163     }
00164     if (update_demand == UPD_DEMAND_SCHED
00165         || update_demand == UPD_DEMAND_ASYNC)
00166         update_removewants();
00167     /* flush all mem file objects to disk */
00168     ef_flush(EF_NATION);
00169     ef_flush(EF_SECTOR);
00170     ef_flush(EF_SHIP);
00171     ef_flush(EF_PLANE);
00172     ef_flush(EF_LAND);
00173     delete_old_announcements();
00174     delete_old_news();
00175     /* Clear all the telegram flags */
00176     for (cn = 0; cn < MAXNOC; cn++)
00177         clear_telegram_is_new(cn);
00178     logerror("End update");
00179 }

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