]> git.pond.sub.org Git - empserver/blob - src/lib/update/populace.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / update / populace.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  populace.c: Return workforce available
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  */
33
34 #include <config.h>
35
36 #include "misc.h"
37 #include "sect.h"
38 #include "nat.h"
39 #include "file.h"
40 #include "path.h"
41 #include "xy.h"
42 #include "land.h"
43 #include "update.h"
44 #include "subs.h"
45 #include "gen.h"
46 #include "common.h"
47 #include "lost.h"
48
49 void
50 populace(struct natstr *np, struct sctstr *sp, int etu)
51 {
52     float hap;
53     float tech;
54     float edu;
55     float pct;
56     int n;
57     int civ = sp->sct_item[I_CIVIL];
58     int mil = sp->sct_item[I_MILIT];
59
60     if (civ == 0 && mil > 0) {
61         sp->sct_work = 100;
62         sp->sct_loyal = 0;
63         sp->sct_oldown = sp->sct_own;
64     }
65     if (!civ && !mil && !sp->sct_item[I_UW]
66         && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) {
67         makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
68         sp->sct_own = 0;
69         sp->sct_oldown = 0;
70         return;
71     }
72     if (sp->sct_own != sp->sct_oldown && sp->sct_loyal == 0) {
73         sp->sct_oldown = sp->sct_own;
74     }
75
76     hap = np->nat_level[NAT_HLEV];
77     edu = np->nat_level[NAT_ELEV];
78     tech = np->nat_level[NAT_TLEV];
79     pct = (double)((tech - 40) / 40.0 + edu / 3.0);
80     if (sp->sct_own == sp->sct_oldown && hap < pct &&
81         chance((double)(((double)pct - (double)hap) / (double)5.0))) {
82         /*
83          * zap the loyalty of unhappy civilians.
84          * there is a 20% chance per hap point below the
85          * "recommended" amount of this happening.
86          */
87         n = roundavg(etu * 0.125);
88         if (n == 0)
89             n = 1;
90         n = sp->sct_loyal + (random() % n) + 1;
91         if (n > 127)
92             n = 127;
93         sp->sct_loyal = n;
94     }
95     if (sp->sct_loyal > 65 && mil < civ / 20) {
96         int work_red;
97
98         work_red = sp->sct_loyal - (50 + (random() % 15));
99         n = sp->sct_work - work_red;
100         if (n < 0)
101             n = 0;
102         sp->sct_work = n;
103         if (chance((double)work_red / 1000.0)) {
104             /*
105              * small chance of rebellion...
106              * if work_red is (max) 67,
107              * then revolt chance is 6.7%
108              */
109             revolt(sp);
110         } else if (chance(.30) && sp->sct_own)
111             wu(0, sp->sct_own, "Civil unrest in %s!\n", ownxy(sp));
112     }
113     if (sp->sct_loyal) {
114         n = sp->sct_loyal;
115         if (chance(0.75))
116             n -= roundavg(etu * 0.25);
117         else
118             n += roundavg(etu * 0.125);
119         if (n < 0)
120             n = 0;
121         else if (n > 127)
122             n = 127;
123         sp->sct_loyal = n;
124         if (sp->sct_loyal == 0) {
125             if (sp->sct_oldown != sp->sct_own) {
126                 wu(0, sp->sct_own,
127                    "Sector %s is now fully yours\n", ownxy(sp));
128                 sp->sct_oldown = sp->sct_own;
129             }
130         }
131     }
132     return;
133 }
134
135 int
136 total_work(int sctwork, int etu, int civil, int milit, int uw, int maxpop)
137 {
138     if (civil > maxpop)
139         civil = maxpop;
140     if (milit > maxpop)
141         milit = maxpop;
142     if (uw > maxpop)
143         uw = maxpop;
144
145     return (civil * sctwork / 100.0 + milit * 0.4 + uw) * etu / 100.0;
146 }