2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * populace.c: Return workforce available
29 * Known contributors to this file:
31 * Markus Armbruster, 2004-2016
39 #include "prototypes.h"
45 populace(struct sctstr *sp, int etu)
47 struct natstr *np = getnatp(sp->sct_own);
50 int civ = sp->sct_item[I_CIVIL];
51 int mil = sp->sct_item[I_MILIT];
56 sp->sct_oldown = sp->sct_own;
58 if (sp->sct_own && !civ && !mil
59 && !has_units(sp->sct_x, sp->sct_y, sp->sct_own)) {
60 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
65 if (!civ && !mil && !sp->sct_item[I_UW])
68 if (sp->sct_own != sp->sct_oldown && sp->sct_loyal == 0) {
69 sp->sct_oldown = sp->sct_own;
72 hap = np->nat_level[NAT_HLEV];
74 if (sp->sct_own == sp->sct_oldown && hap < pct &&
75 chance((pct - hap) / 5.0)) {
77 * zap the loyalty of unhappy civilians.
78 * there is a 20% chance per hap point below the
79 * "recommended" amount of this happening.
81 n = roundavg(etu * 0.125);
84 n = sp->sct_loyal + roll(n);
89 if (sp->sct_loyal > 65 && mil < civ / 20) {
92 work_red = sp->sct_loyal - (49 + roll(15));
93 n = sp->sct_work - work_red;
97 if (chance(work_red / 1000.0)) {
99 * small chance of rebellion...
100 * if work_red is (max) 67,
101 * then revolt chance is 6.7%
104 } else if (chance(.30) && sp->sct_own)
105 wu(0, sp->sct_own, "Civil unrest in %s!\n", ownxy(sp));
110 n -= roundavg(etu * 0.25);
112 n += roundavg(etu * 0.125);
113 sp->sct_loyal = LIMIT_TO(n, 0, 127);
114 if (sp->sct_loyal == 0) {
115 if (sp->sct_oldown != sp->sct_own) {
117 "Sector %s is now fully yours\n", ownxy(sp));
118 sp->sct_oldown = sp->sct_own;
126 total_work(int sctwork, int etu, int civil, int milit, int uw,
129 if (civil > maxworkers)
131 if (milit > maxworkers)
136 return roundavg((civil * sctwork / 100.0 + milit / 2.5 + uw)