]> git.pond.sub.org Git - empserver/blob - src/lib/subs/rej.c
31ba58ef97997d847e36417b6c59100e47690080
[empserver] / src / lib / subs / rej.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  *  rej.c: Various relations setting routines
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1994
32  */
33
34 #include "misc.h"
35 #include "nat.h"
36 #include "file.h"
37 #include "news.h"
38 #include "player.h"
39 #include "prototypes.h"
40 #include "optlist.h"
41
42 extern s_char *relates[];
43 extern int update_pending;
44
45 int
46 setrel(natid us, natid them, int rel)
47 {
48         struct  natstr *mynp;
49         struct  natstr *themnp;
50         s_char  *myname = cname(us);
51         s_char  *themname;
52         int     oldrel;
53         s_char *whichway;
54         int     n_up = 0;
55         int     n_down = 0;
56         s_char  *addendum = 0;
57         int     theirrel;
58         extern int      War_Cost;
59
60         if (rel < AT_WAR)
61                 rel = AT_WAR;
62         if (rel > ALLIED)
63                 rel = ALLIED;
64         if (!(mynp = getnatp(us)))
65                 return RET_FAIL;
66         if (!(themnp = getnatp(them)))
67                 return RET_FAIL;
68         if ((oldrel = getrel(mynp, them)) == rel)
69                 return RET_FAIL;
70         themname = cname(them);
71         if (rel > oldrel)
72                 whichway = "upgraded";
73         else
74                 whichway = "downgraded";
75         if (rel == ALLIED) {
76                 addendum = "Congratulations!";
77                 n_up = N_DECL_ALLY;
78         } else if (rel == FRIENDLY) {
79                 n_up = N_UP_FRIENDLY;
80                 n_down = N_DOWN_FRIENDLY;
81         } else if (rel == NEUTRAL) {
82                 n_up = N_UP_NEUTRAL;
83                 n_down = N_DOWN_NEUTRAL;
84         } else if (rel == HOSTILE) {
85                 addendum = "Another cold war...";
86                 n_up = N_UP_HOSTILE;
87                 n_down = N_DOWN_HOSTILE;
88         } else if (rel < HOSTILE) {
89           if (opt_SLOW_WAR) {
90                 struct  natstr  *natp2;
91                 double  cost;
92
93                 if (!player->god) {
94                         natp2 = themnp;
95                         theirrel = getrel(natp2,us);
96                         if (theirrel <= MOBILIZATION) {
97                                 rel = theirrel;
98                                 cost = 0;
99                         } else if (us == player->cnum && !update_pending) {
100                                 if (mynp->nat_money < War_Cost){
101                                         mpr(us, "You don't have the money!\n");
102                                         return RET_FAIL;
103                                 }
104                                 rel = MOBILIZATION;
105                                 cost = War_Cost;
106                         } else { /* nreport is forcing us to decl war */
107                                 return RET_FAIL;
108                         }
109                         if (rel >= oldrel) {
110                                 if (us == player->cnum && !update_pending)
111                                     mpr(us, "No change required for that!\n");
112                                 return RET_FAIL;
113                         }
114                         player->dolcost += cost;
115                 }
116           }
117           addendum = "Declaration made (give 'em hell).";
118           n_down = N_DECL_WAR;
119         }
120
121         if (addendum && us == player->cnum && !update_pending)
122                 pr("%s\n", addendum);
123         mpr(us, "Diplomatic relations with %s %s to \"%s\".\n", themname, whichway, relates[rel]);
124         if(!(getrejects(us, themnp) & REJ_TELE))
125                 mpr(them,
126                     "Country %s (#%d) has %s their relations with you to \"%s\"!\n", myname, us, whichway, relates[rel]);
127
128         putrel(mynp, them, rel);
129         putnat(mynp);
130
131         if (!player->god) {
132                 if (oldrel == ALLIED)
133                         nreport(us, N_DIS_ALLY, them, 1);
134                 else if (oldrel < HOSTILE && rel >= HOSTILE)
135                         nreport(us, N_DIS_WAR, them, 1);
136                 if (rel > oldrel)
137                         nreport(us, n_up, them, 1);
138                 else
139                         nreport(us, n_down, them, 1);
140         }
141
142         return RET_OK;
143 }
144
145 int
146 setcont(natid us, natid them, int contact)
147 {
148         struct  natstr *np;
149
150         if ((np = getnatp(us)) == 0)
151                 return 0;
152         putcontact(np, them, contact);
153         putnat(np);
154         return 1;
155 }
156
157 int
158 setrej(natid us, natid them, int how, int what)
159 {
160         struct  natstr *np;
161
162         if ((np = getnatp(us)) == 0)
163                 return 0;
164         putreject(np, them, how, what);
165         putnat(np);
166         return 1;
167 }