]> git.pond.sub.org Git - empserver/blob - src/lib/update/populace.c
Import of Empire 4.2.12
[empserver] / src / lib / update / populace.c
1 /*
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
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 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.
25  *
26  *  ---
27  *
28  *  populace.c: Return workforce available
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  */
33
34 #include "misc.h"
35 #include "var.h"
36 #include "sect.h"
37 #include "nat.h"
38 #include "news.h"
39 #include "var.h"
40 #include "file.h"
41 #include "path.h"
42 #include "xy.h"
43 #include "land.h"
44 #include "budg.h"
45 #include "update.h"
46 #include "subs.h"
47 #include "gen.h"
48 #include "common.h"
49 #include "lost.h"
50
51 void
52 populace(struct natstr *np, register struct sctstr *sp, register int *vec, int etu)
53 {
54         float   hap;
55         float   tech;
56         float   edu;
57         float   pct;
58         int     n;
59
60         if (vec[I_CIVIL] == 0 && vec[I_MILIT] > 0) {
61                 sp->sct_work = 100;
62                 sp->sct_loyal = 0;
63                 sp->sct_oldown = sp->sct_own;
64         }
65         if (!vec[I_CIVIL] && !vec[I_MILIT] && !vec[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) n = 1;
89                 n = sp->sct_loyal + (random() % n) + 1;
90                 if (n > 127)
91                         n = 127;
92                 sp->sct_loyal = n;
93         }
94         if (sp->sct_loyal > 65 && vec[I_MILIT] < vec[I_CIVIL]/20) {
95                 int     work_red;
96
97                 work_red = sp->sct_loyal - (50 + (random() % 15));
98                 n = sp->sct_work - work_red;
99                 if (n < 0)
100                         n = 0;
101                 sp->sct_work = n;
102                 if (chance((double)work_red/1000.0)) {
103                         /*
104                          * small chance of rebellion...
105                          * if work_red is (max) 67,
106                          * then revolt chance is 6.7%
107                          */
108                         revolt(sp);
109                 } else if (chance(.30) && sp->sct_own)
110                         wu(0, sp->sct_own, "Civil unrest in %s!\n", ownxy(sp));
111         }
112         if (sp->sct_loyal) {
113                 n = sp->sct_loyal;
114                 if (chance(0.75))
115                         n -= roundavg(etu * 0.25);
116                 else
117                         n += roundavg(etu * 0.125);
118                 if (n < 0)
119                         n = 0;
120                 else if (n > 127)
121                         n = 127;
122                 sp->sct_loyal = n;
123                 if (sp->sct_loyal == 0) {
124                         if (sp->sct_oldown != sp->sct_own) {
125                                 wu(0, sp->sct_own,
126                                         "Sector %s is now fully yours\n",
127                                         ownxy(sp));
128                                 sp->sct_oldown = sp->sct_own;
129                         }
130                         sp->sct_loyal = 0;
131                 }
132         }
133         return;
134 }
135
136 int
137 total_work(register int sctwork, register int etu, register int civil, register int milit, register int uw)
138 {
139         return ((int)((((civil * sctwork) / 100.0 +
140                 (milit * 2 / 5.0) + uw)) * etu) / 100);
141 }