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:
52 static int grow_people(struct sctstr *, register int,
53 register struct natstr *, int *, int,
55 static int growfood(struct sctstr *, short *, int, int);
56 static void starvation(struct sctstr *);
57 static void trunc_people(struct sctstr *, register struct natstr *,
61 * feed the individual sector
65 do_feed(struct sctstr *sp, struct natstr *np, short *vec,
66 int *workp, int *bp, int etu)
76 /* grow people & stuff */
77 sctwork = sp->sct_work;
79 maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
80 civvies = (vec[I_CIVIL] > maxpop) ? maxpop : vec[I_CIVIL];
81 uws = (vec[I_UW] > maxpop) ? maxpop : vec[I_UW];
82 mil = (vec[I_MILIT] > maxpop) ? maxpop : vec[I_MILIT];
83 work_avail = total_work(sctwork, etu, civvies, mil, uws);
84 if (opt_ROLLOVER_AVAIL) {
85 if (sp->sct_type == sp->sct_newtype) {
86 work_avail += sp->sct_avail;
90 people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
91 if (sp->sct_type != SCT_SANCT) {
92 if (opt_NOFOOD == 0) {
93 if (vec[I_FOOD] < 1 + etu * people * eatrate) {
94 /* need to grow "emergency rations" */
96 growfood(sp, vec, (int)(work_avail / 2),
98 /* It's twice as hard to grow those than norm */
99 pt_bg_nmbr(bp, sp, I_MAX + 1, work_avail);
100 if (!player->simulation)
101 sp->sct_avail = work_avail;
103 if ((vec[I_FOOD] < 1 + etu * people * eatrate) &&
104 (sp->sct_own == sp->sct_oldown)) {
106 /* steal food from warehouses, headquarters,
107 supply ships in port, or supply units */
110 needed = ldround((double)(1 + etu * people * eatrate), 1);
112 /* Now, find some food */
113 vec[I_FOOD] = supply_commod(sp->sct_own, sp->sct_x,
114 sp->sct_y, I_FOOD, needed);
118 starved = feed_people(vec, etu, &needed);
119 if ((starved > 0 && sp->sct_own) && (!player->simulation)) {
120 /* don't report POGO starvation */
121 wu(0, sp->sct_own, "%d starved in %s.\n", starved,
122 xyas(sp->sct_x, sp->sct_y, sp->sct_own));
124 nreport(sp->sct_own, N_DIE_FAMINE, 0, 1);
127 if (!player->simulation)
131 if (sp->sct_work < 100)
132 sctwork = sp->sct_work + 8 + (random() % 15);
135 if (!player->simulation)
136 sp->sct_work = sctwork;
137 dummy = grow_people(sp, etu, np, &work_avail, sctwork, vec);
140 sctwork = sp->sct_work = 100;
141 /* Here is where we truncate extra people, always */
142 trunc_people(sp, np, vec);
144 pt_bg_nmbr(bp, sp, I_CIVIL, vec[I_CIVIL]);
145 pt_bg_nmbr(bp, sp, I_UW, vec[I_UW]);
146 pt_bg_nmbr(bp, sp, I_MILIT, vec[I_MILIT]);
147 if (work_avail > 999) work_avail = 999;
153 growfood(struct sctstr *sp, short *vec, int work, int etu)
160 /* I'm being very nice and commenting out this so players
161 * won't whine about starvation
162 if (sp->sct_fertil == 0 || work == 0)
165 food_workers = work * fcrate;
166 food_fertil = etu * sp->sct_fertil * fgrate;
168 if (food > food_workers)
171 * be nice; grow minimum one food unit.
172 * This makes life simpler for the player.
174 vec[I_FOOD] += (int)food;
175 if (vec[I_FOOD] == 0)
177 if (vec[I_FOOD] > ITEM_MAX)
178 vec[I_FOOD] = ITEM_MAX;
179 work_used = (int)food / fcrate;
184 * returns the number who starved, if any.
187 feed_people(short *vec, int etu, int *needed)
199 total_people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
200 food_eaten = etu * eatrate * total_people;
201 ifood_eaten = (int)food_eaten;
202 if (food_eaten - ifood_eaten > 0)
204 if (ifood_eaten <= 1)
208 if (ifood_eaten > vec[I_FOOD]) {
209 *needed = ifood_eaten - vec[I_FOOD];
210 can_eat = vec[I_FOOD] / (etu * eatrate);
211 /* only want to starve off at most 1/2 the populace. */
212 if (can_eat < total_people / 2)
213 can_eat = total_people / 2;
215 to_starve = total_people - can_eat;
216 while (to_starve && vec[I_UW]) {
221 while (to_starve && vec[I_CIVIL]) {
226 while (to_starve && vec[I_MILIT]) {
234 vec[I_FOOD] -= roundavg(food_eaten);
240 * Truncate any extra people that may be around
243 trunc_people(struct sctstr *sp, register struct natstr *np,
246 int maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
248 if (vec[I_CIVIL] > maxpop)
249 vec[I_CIVIL] = maxpop;
250 if (vec[I_UW] > maxpop)
255 * Grow babies, and add to populace.
256 * XXX Might think about dropping in a birth
257 * rate limitation on countries with high tech
258 * production? Maybe with just high education?
261 grow_people(struct sctstr *sp, register int etu,
262 register struct natstr *np, int *workp, int sctwork,
269 int maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
273 if (vec[I_CIVIL] < maxpop) {
274 new_birth = (int)roundavg(obrate * (double)(etu * vec[I_CIVIL]));
276 new_food = (int)(0.5 + maxpop / (2.0 * babyeat));
277 else /* we are using food */
278 new_food = (int)(0.5 + vec[I_FOOD] / (2.0 * babyeat));
281 if (newciv > new_food)
283 /* Now, check max pops */
284 if ((vec[I_CIVIL] + newciv) > maxpop)
285 newciv = maxpop - vec[I_CIVIL];
286 vec[I_CIVIL] += newciv;
288 if (vec[I_UW] < maxpop) {
292 new_birth = (int)roundavg(uwbrate * (double)(etu * vec[I_UW]));
294 new_food = (int)(0.5 + maxpop / (2.0 * babyeat));
295 else /* food is important */
296 new_food = (int)(0.5 + vec[I_FOOD] / (2.0 * babyeat));
299 if (newuw > new_food)
301 /* Now, check max pops */
302 if ((vec[I_UW] + newuw) > maxpop)
303 newuw = maxpop - vec[I_UW];
307 * subtract the baby eat food (if we are using FOOD) and return
310 if (opt_NOFOOD == 0 && (newciv || newuw))
311 vec[I_FOOD] -= roundavg((newciv + newuw) * babyeat);
312 *workp += total_work(sctwork, etu, newciv, 0, newuw);
313 return newciv + newuw;
317 * percentage of people who starved
320 starvation(struct sctstr *sp)
323 sp->sct_loyal += (random() % 8) + 2;