]> git.pond.sub.org Git - empserver/blob - src/lib/commands/anti.c
Update copyright notice.
[empserver] / src / lib / commands / anti.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, 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  *  anti.c: Take action against che
29  * 
30  *  Known contributors to this file:
31  *     Pat Loney, 1992
32  *     Steve McClure, 1997
33  */
34
35 #include <config.h>
36
37 #include <ctype.h>
38 #include "commands.h"
39 #include "item.h"
40 #include "lost.h"
41 #include "optlist.h"
42
43 /*
44  * format: anti <SECT>
45  */
46 int
47 anti(void)
48 {
49     struct sctstr sect;
50     int nsect;
51     struct nstr_sect nstr;
52     int mil, che, target;
53     int avail_mil;
54     int amil, ache;
55     int milkilled, chekilled;
56     double odds, damil, dache;
57     int mob;
58     int n_cheleft;
59
60     if (!snxtsct(&nstr, player->argp[1]))
61         return RET_SYN;
62     prdate();
63     nsect = 0;
64     while (nxtsct(&nstr, &sect)) {
65         if (!player->owner)
66             continue;
67         if (nsect++ == 0) {
68             pr("  sect    subversion activity report\n");
69             pr("  ----    --------------------------\n");
70         }
71         mil = sect.sct_item[I_MILIT];
72         che = sect.sct_che;
73         target = sect.sct_che_target;
74         avail_mil = sect.sct_mobil / 2;
75         if (mil <= avail_mil)
76             avail_mil = mil;
77         prxy("%4d,%-4d ", sect.sct_x, sect.sct_y, player->cnum);
78         if (avail_mil <= 0) {
79             pr("No available mil or mob in sector.\n");
80             continue;
81         }
82         pr("Sector mobility/troop strength will allow %d troops to engage.\n",
83            avail_mil);
84
85         if (target == player->cnum) {
86             amil = mil;
87             ache = che;
88             milkilled = 0;
89             chekilled = 0;
90             mob = sect.sct_mobil;
91             while (amil != 0 && ache != 0 && mob > 1) {
92                 damil = amil;
93                 dache = ache;
94                 odds = (dache * 2.0 / (damil + dache));
95                 odds /= hap_fact(getnatp(sect.sct_own),
96                                  getnatp(sect.sct_oldown));
97                 mob = mob - 2;
98                 if (chance(odds)) {
99                     amil = amil - 1;
100                     milkilled = milkilled + 1;
101                 } else {
102                     ache = ache - 1;
103                     chekilled = chekilled + 1;
104                 }
105             }
106             if (mil - milkilled > 0) {
107                 sect.sct_mobil = sect.sct_mobil - chekilled - milkilled;
108                 sect.sct_item[I_MILIT] = mil - milkilled;
109                 if (ache == 0)
110                     sect.sct_che_target = 0;
111                 sect.sct_che = ache;
112                 putsect(&sect);
113                 pr("          Body count:  Military %d - Guerillas %d.\n",
114                    milkilled, chekilled);
115                 if (ache == 0) {
116                     pr("          Partisans cleared out of this sector for now.\n");
117                 } else {
118                     pr("          Partisans still active in this sector.\n");
119                 }
120             } else {
121                 if (opt_MOB_ACCESS) {
122                     sect.sct_mobil =
123                         -(etu_per_update / sect_mob_neg_factor);
124                 } else {
125                     sect.sct_mobil = 0;
126                 }
127                 sect.sct_loyal = sect.sct_loyal * 0.5;
128                 n_cheleft = (random() % 4);
129                 /* 75% chance some che will get left */
130                 if (n_cheleft) {
131                     /* Ok, now leave anywhere from 16% to 25% of the che */
132                     n_cheleft = (ache / (n_cheleft + 3));
133                     ache -= n_cheleft;
134                     sect.sct_che = n_cheleft;
135                 } else {
136                     sect.sct_che = 0;
137                     sect.sct_che_target = 0;
138                 }
139                 sect.sct_item[I_MILIT] = ache;
140                 if (sect.sct_own == sect.sct_oldown)
141                     sect.sct_oldown = 0;
142                 makelost(EF_SECTOR, sect.sct_own, 0,
143                          sect.sct_x, sect.sct_y);
144                 makenotlost(EF_SECTOR, sect.sct_oldown, 0,
145                             sect.sct_x, sect.sct_y);
146                 sect.sct_own = sect.sct_oldown;
147                 sect.sct_off = 1;       /* Turn the sector off */
148                 putsect(&sect);
149                 pr("          Partisans take over the sector.  You blew it.\n");
150                 wu(0, sect.sct_oldown,
151                    "Sector %s regained from Partisan activity.\n",
152                    xyas(nstr.x, nstr.y, sect.sct_oldown));
153             }
154         } else {
155             pr("          Body count:  Military 0 - Guerillas 0.\n");
156             pr("          Partisans cleared out of this sector for now.\n");
157         }
158     }
159     pr("%d sector%s\n", nsect, splur(nsect));
160     return RET_OK;
161 }