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