2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * human.c: Food related functions
30 * Known contributors to this file:
53 * feed the individual sector
57 do_feed(register struct sctstr *sp, register struct natstr *np, int *vec, int *workp, int *bp, int etu)
59 extern double eatrate;
68 /* grow people & stuff */
69 sctwork = sp->sct_work;
71 maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
72 civvies = (vec[I_CIVIL] > maxpop) ? maxpop : vec[I_CIVIL];
73 uws = (vec[I_UW] > maxpop) ? maxpop : vec[I_UW];
74 mil = (vec[I_MILIT] > maxpop) ? maxpop : vec[I_MILIT];
75 work_avail = total_work(sctwork, etu, civvies, mil, uws);
77 people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
78 if (sp->sct_type != SCT_SANCT) {
79 if (opt_NOFOOD == 0) {
80 if (vec[I_FOOD] < 1 + etu * people * eatrate) {
81 /* need to grow "emergency rations" */
83 growfood(sp, vec, (int)(work_avail/2), etu));
84 /* It's twice as hard to grow those than norm*/
85 pt_bg_nmbr(bp, sp, I_MAX+1, work_avail);
86 if (!player->simulation)
87 sp->sct_avail = work_avail;
89 if ((vec[I_FOOD] < 1 + etu * people * eatrate) &&
90 (sp->sct_own == sp->sct_oldown)){
92 /* steal food from warehouses, headquarters,
93 supply ships in port, or supply units */
96 needed = ldround((double)(1+etu*people*eatrate),1);
98 /* Now, find some food */
99 vec[I_FOOD] = supply_commod(sp->sct_own,sp->sct_x,
100 sp->sct_y,I_FOOD,needed);
104 starved = feed_people(vec, etu, &needed);
105 if ((starved > 0 && sp->sct_own) && (!player->simulation)) {
106 /* don't report POGO starvation */
107 wu(0, sp->sct_own, "%d starved in %s.\n", starved,
108 xyas(sp->sct_x, sp->sct_y, sp->sct_own));
110 nreport(sp->sct_own, N_DIE_FAMINE, 0, 1);
113 if (!player->simulation)
117 if (sp->sct_work < 100)
118 sctwork = sp->sct_work + 8 + (random() % 15);
121 if (!player->simulation)
122 sp->sct_work = sctwork;
123 dummy = grow_people(sp, etu, np, &work_avail, sctwork, vec);
126 sctwork = sp->sct_work = 100;
127 /* Here is where we truncate extra people, always */
128 trunc_people(sp, np, vec);
130 pt_bg_nmbr(bp, sp, I_CIVIL, vec[I_CIVIL]);
131 pt_bg_nmbr(bp, sp, I_UW, vec[I_UW]);
132 pt_bg_nmbr(bp, sp, I_MILIT, vec[I_MILIT]);
138 growfood(struct sctstr *sp, register int *vec, int work, int etu)
140 extern double fgrate;
141 extern double fcrate;
147 /* I'm being very nice and commenting out this so players
148 * won't whine about starvation
149 if (sp->sct_fertil == 0 || work == 0)
152 food_workers = work * fcrate;
153 food_fertil = etu * sp->sct_fertil * fgrate;
155 if (food > food_workers)
158 * be nice; grow minimum one food unit.
159 * This makes life simpler for the player.
161 vec[I_FOOD] += (int) food;
162 if (vec[I_FOOD] == 0)
164 if (vec[I_FOOD] > 9999)
166 work_used = (int) food / fcrate;
171 * returns the number who starved, if any.
174 feed_people(register int *vec, int etu, int *needed)
176 extern double eatrate;
186 food_eaten = (double)(((double)etu * (double)eatrate) *
187 (double)(vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]));
192 if (food_eaten > vec[I_FOOD]) {
193 *needed = food_eaten - vec[I_FOOD];
194 if ((double)(*needed) < (double)(food_eaten - (double)vec[I_FOOD]))
196 if (opt_NEW_STARVE) {
197 can_eat = (vec[I_FOOD] / (etu * eatrate));
198 total_people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
200 /* only want to starve off at most 1/2 the populace. */
201 if (can_eat < (total_people/2))
202 can_eat = total_people/2;
204 to_starve = total_people - can_eat;
205 while(to_starve && vec[I_UW]){
210 while(to_starve && vec[I_CIVIL]){
215 while(to_starve && vec[I_MILIT]){
223 else { /* ! opt_NEW_STARVE */
225 people_left = (vec[I_FOOD] + 0.01) / (food_eaten + 0.01);
226 starved = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
227 /* only want to starve off at most 1/2 the populace. */
228 if (people_left < 0.5)
230 vec[I_CIVIL] = (int) (vec[I_CIVIL] * people_left);
231 vec[I_MILIT] = (int) (vec[I_MILIT] * people_left);
232 vec[I_UW] = (int) (vec[I_UW] * people_left);
233 starved -= vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
235 } /* end opt_NEW_STARVE */
237 vec[I_FOOD] -= roundavg(food_eaten);
243 * Truncate any extra people that may be around
246 trunc_people(struct sctstr *sp, register struct natstr *np, register int *vec)
248 int maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
250 if (vec[I_CIVIL] > maxpop)
251 vec[I_CIVIL] = maxpop;
252 if (vec[I_UW] > maxpop)
257 * Grow babies, and add to populace.
258 * XXX Might think about dropping in a birth
259 * rate limitation on countries with high tech
260 * production? Maybe with just high education?
262 int grow_people(struct sctstr *sp, register int etu, register struct natstr *np, int *workp, int sctwork, register int *vec)
264 extern double obrate;
265 extern double uwbrate;
266 extern double babyeat;
271 int maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
275 if (vec[I_CIVIL] < maxpop) {
276 new_birth = (int) roundavg(obrate * (double)(etu * vec[I_CIVIL]));
278 new_food = (int) (0.5 + maxpop / (2.0 * babyeat));
279 else /* we are using food */
280 new_food = (int) (0.5 + vec[I_FOOD] / (2.0 * babyeat));
283 if (newciv > new_food)
285 /* Now, check max pops */
286 if ((vec[I_CIVIL] + newciv) > maxpop)
287 newciv = maxpop - vec[I_CIVIL];
288 vec[I_CIVIL] += newciv;
290 if (vec[I_UW] < maxpop) {
294 new_birth = (int) roundavg(uwbrate * (double)(etu * vec[I_UW]));
296 new_food = (int) (0.5 + maxpop / (2.0 * babyeat));
297 else /* food is important */
298 new_food = (int) (0.5 + vec[I_FOOD] / (2.0 * babyeat));
301 if (newuw > new_food)
303 /* Now, check max pops */
304 if ((vec[I_UW] + newuw) > maxpop)
305 newuw = maxpop - vec[I_UW];
309 * subtract the baby eat food (if we are using FOOD) and return
312 if (opt_NOFOOD == 0 && (newciv || newuw))
313 vec[I_FOOD] -= roundavg((newciv + newuw) * babyeat);
314 *workp += total_work(sctwork, etu, newciv, 0, newuw);
315 return newciv + newuw;
319 * percentage of people who starved
322 starvation(struct sctstr *sp)
325 sp->sct_loyal += (random() % 8) + 2;