00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include <math.h>
00037 #include "commands.h"
00038 #include "item.h"
00039 #include "land.h"
00040 #include "optlist.h"
00041 #include "path.h"
00042 #include "ship.h"
00043
00044 static void starv_sects(char *range);
00045 static void starv_ships(char *range);
00046 static void starv_units(char *range);
00047 static void sect_hdr(void);
00048 static void ship_hdr(void);
00049 static void unit_hdr(void);
00050
00051 int
00052 starve(void)
00053 {
00054 int do_sects = 0;
00055 int do_ships = 0;
00056 int do_units = 0;
00057 char *range;
00058
00059 if (opt_NOFOOD) {
00060 pr("No food is required in this game\n");
00061 return RET_OK;
00062 }
00063
00064 range = "*";
00065 if (!player->argp[1]) {
00066 do_sects = do_ships = do_units = 1;
00067 } else if (*(player->argp[1]) == 's') {
00068 do_ships = 1;
00069 if (player->argp[2])
00070 range = player->argp[2];
00071 } else if (*(player->argp[1]) == 'l') {
00072 do_units = 1;
00073 if (player->argp[2])
00074 range = player->argp[2];
00075 } else {
00076 do_sects = 1;
00077 range = player->argp[1];
00078 }
00079 player->simulation = 1;
00080 prdate();
00081 if (do_sects)
00082 starv_sects(range);
00083 if (do_ships)
00084 starv_ships(range);
00085 if (do_units)
00086 starv_units(range);
00087 player->simulation = 0;
00088 return RET_OK;
00089 }
00090
00091 static void
00092 starv_people(short *vec, int victims)
00093 {
00094 pr(" will starve %d people. %.0f more food needed\n", victims,
00095 ceil(food_needed(vec, etu_per_update) - vec[I_FOOD]));
00096 }
00097
00098 static void
00099 starv_sects(char *range)
00100 {
00101 struct nstr_sect nstr;
00102 struct sctstr sect;
00103 int nsect = 0;
00104 int s, save;
00105
00106 if (!snxtsct(&nstr, range))
00107 return;
00108 while (nxtsct(&nstr, §)) {
00109 if (!player->owner)
00110 continue;
00111 if (sect.sct_type == SCT_SANCT)
00112 continue;
00113
00114
00115
00116
00117
00118
00119
00120 save = sect.sct_item[I_FOOD];
00121 if (sect.sct_item[I_FOOD] == 0)
00122 sect.sct_item[I_FOOD] = 1;
00123 s = famine_victims(sect.sct_item, etu_per_update);
00124 sect.sct_item[I_FOOD] = save;
00125 if (s == 0)
00126 continue;
00127
00128 if (nsect++ == 0)
00129 sect_hdr();
00130 if (player->god)
00131 pr("%3d ", sect.sct_own);
00132 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
00133 pr(" %c", dchr[sect.sct_type].d_mnem);
00134 pr(" %c", sect.sct_own != sect.sct_oldown ? '*' : ' ');
00135 if (sect.sct_newtype != sect.sct_type)
00136 pr("%c", dchr[sect.sct_newtype].d_mnem);
00137 else
00138 pr(" ");
00139 pr("%4d%%", sect.sct_effic);
00140 starv_people(sect.sct_item, s);
00141 }
00142 if (nsect == 0) {
00143 if (player->argp[1])
00144 pr("%s: No sector(s)\n", player->argp[1]);
00145 else
00146 pr("%s: No sector(s)\n", "");
00147 return;
00148 } else
00149 pr("%d sector%s\n", nsect, splur(nsect));
00150 return;
00151 }
00152
00153 static void
00154 sect_hdr(void)
00155 {
00156 if (player->god)
00157 pr(" ");
00158 pr("Starvation \n");
00159 if (player->god)
00160 pr("own ");
00161 pr(" sect eff ");
00162 pr("\n");
00163 }
00164
00165 static void
00166 starv_ships(char *range)
00167 {
00168 struct nstr_item ni;
00169 struct shpstr ship;
00170 int nship = 0;
00171 int s;
00172
00173 if (!snxtitem(&ni, EF_SHIP, range))
00174 return;
00175
00176 while (nxtitem(&ni, &ship)) {
00177 if (!player->owner || !ship.shp_own)
00178 continue;
00179
00180 s = famine_victims(ship.shp_item, etu_per_update);
00181 if (s == 0)
00182 continue;
00183 if (nship++ == 0)
00184 ship_hdr();
00185 if (player->god)
00186 pr("%3d ", ship.shp_own);
00187 pr("%5d ", ship.shp_uid);
00188 pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
00189 starv_people(ship.shp_item, s);
00190 }
00191 if (nship == 0) {
00192 if (range)
00193 pr("%s: No ship(s)\n", range);
00194 else
00195 pr("%s: No ship(s)\n", "");
00196 return;
00197 } else
00198 pr("%d ship%s\n", nship, splur(nship));
00199 return;
00200 }
00201
00202 static void
00203 ship_hdr(void)
00204 {
00205 if (player->god)
00206 pr(" ");
00207 pr("Starvation \n");
00208 if (player->god)
00209 pr("own ");
00210 pr(" shp# ship type \n");
00211 }
00212
00213 static void
00214 starv_units(char *range)
00215 {
00216 struct nstr_item ni;
00217 struct lndstr land;
00218 int nunit = 0;
00219 int s;
00220
00221 if (!snxtitem(&ni, EF_LAND, range))
00222 return;
00223
00224 while (nxtitem(&ni, &land)) {
00225 if (!player->owner || !land.lnd_own)
00226 continue;
00227
00228 s = famine_victims(land.lnd_item, etu_per_update);
00229 if (s == 0)
00230 continue;
00231 if (nunit++ == 0)
00232 unit_hdr();
00233 if (player->god)
00234 pr("%3d ", land.lnd_own);
00235 pr("%5d ", land.lnd_uid);
00236 pr("%-16.16s ", lchr[(int)land.lnd_type].l_name);
00237 starv_people(land.lnd_item, s);
00238 }
00239 if (nunit == 0) {
00240 if (range)
00241 pr("%s: No unit(s)\n", range);
00242 else
00243 pr("%s: No unit(s)\n", "");
00244 return;
00245 } else
00246 pr("%d unit%s\n", nunit, splur(nunit));
00247 return;
00248 }
00249
00250 static void
00251 unit_hdr(void)
00252 {
00253 if (player->god)
00254 pr(" ");
00255 pr("Starvation \n");
00256 if (player->god)
00257 pr("own ");
00258 pr(" lnd# unit type \n");
00259 }