]> git.pond.sub.org Git - empserver/blob - src/lib/subs/trechk.c
Update copyright notice.
[empserver] / src / lib / subs / trechk.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  *  trechk.c: Check to see if an actor has violated a treaty.
29  * 
30  *  Known contributors to this file: 
31  *      Steve McClure, 1998-1999
32  */
33
34 /*
35  * Check to see if an actor has a treaty forbidding a given action,
36  * and if so, see if the actor wishes to break the treaty.
37  * All applicable treaties are checked.  All treaties must be broken
38  * if the action is to be allowed.  Propsed treaties are warned about,
39  * but no mention of broken pending treaties are made in the news.
40  */
41
42 #include <config.h>
43
44 #include "file.h"
45 #include "nat.h"
46 #include "news.h"
47 #include "optlist.h"
48 #include "prototypes.h"
49 #include "treaty.h"
50
51 int
52 trechk(natid actor, natid victim, int provision)
53 {
54     natid cn;
55     char buf[1024];
56     int news_verb;
57     int involved[MAXNOC];
58     struct trtstr treaty;
59     time_t now;
60     int conditions;
61     natid other;
62     int broken;
63     int applied;
64     struct nstr_item nstr;
65
66     if (!opt_TREATIES)
67         return 1;
68     (void)time(&now);
69     broken = 0;
70     applied = 0;
71     for (cn = 0; cn < MAXNOC; cn++)
72         involved[cn] = 0;
73     snxtitem_all(&nstr, EF_TREATY);
74     while (nxtitem(&nstr, &treaty)) {
75         if (treaty.trt_status == TS_FREE)
76             continue;
77         if (treaty.trt_exp < now)
78             continue;
79         if (actor == treaty.trt_cna) {
80             conditions = treaty.trt_acond;
81             other = treaty.trt_cnb;
82         } else if (actor == treaty.trt_cnb) {
83             conditions = treaty.trt_bcond;
84             other = treaty.trt_cna;
85         } else
86             continue;
87         if ((conditions & provision) == 0)
88             continue;
89         if (victim != other) {
90             switch (provision) {
91                 /* These are violations no matter who the victim is */
92             case NEWSHP:
93             case NEWLND:
94             case NEWNUK:
95             case NEWPLN:
96             case TRTENL:
97                 break;
98             default:
99                 /* The rest are only violations against the victim */
100                 continue;
101             }
102         }
103         /* treaty applies to actor */
104         applied++;
105         pr("This action is in contravention of ");
106         if (treaty.trt_status == TS_PROPOSED)
107             pr("pending ");
108         pr(" treaty #%d (with %s)\n", nstr.cur, cname(other));
109         getstring("Do you wish to go ahead anyway? [yn] ", buf);
110         if (*buf == 'n' || *buf == 'N')
111             broken = 0;
112         else
113             broken = 1;
114         if (treaty.trt_status == TS_SIGNED)
115             involved[other]++;
116     }
117     if (applied > 0) {
118         news_verb = N_HONOR_TRE;
119         if (broken > 0)
120             news_verb = N_VIOL_TRE;
121         for (cn = 0; cn < MAXNOC; cn++)
122             if (involved[cn] > 0)
123                 nreport(actor, news_verb, cn, 1);
124     }
125     if (applied && !broken) {
126         /*
127          * if any treaty applied, and none were broken
128          * the intended action is NOT performed.
129          */
130         return 0;
131     }
132     return 1;
133 }