]> git.pond.sub.org Git - empserver/blob - src/lib/subs/rej.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / subs / rej.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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 "misc.h"
37 #include "nat.h"
38 #include "file.h"
39 #include "news.h"
40 #include "player.h"
41 #include "prototypes.h"
42 #include "optlist.h"
43 #include "server.h"
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
59     if (rel < AT_WAR)
60         rel = AT_WAR;
61     if (rel > ALLIED)
62         rel = ALLIED;
63     if (!(mynp = getnatp(us)))
64         return RET_FAIL;
65     if (!(themnp = getnatp(them)))
66         return RET_FAIL;
67     if ((oldrel = getrel(mynp, them)) == rel)
68         return RET_FAIL;
69     themname = cname(them);
70     if (rel > oldrel)
71         whichway = "upgraded";
72     else
73         whichway = "downgraded";
74     if (rel == ALLIED) {
75         addendum = "Congratulations!";
76         n_up = N_DECL_ALLY;
77     } else if (rel == FRIENDLY) {
78         n_up = N_UP_FRIENDLY;
79         n_down = N_DOWN_FRIENDLY;
80     } else if (rel == NEUTRAL) {
81         n_up = N_UP_NEUTRAL;
82         n_down = N_DOWN_NEUTRAL;
83     } else if (rel == HOSTILE) {
84         addendum = "Another cold war...";
85         n_up = N_UP_HOSTILE;
86         n_down = N_DOWN_HOSTILE;
87     } else if (rel < HOSTILE) {
88         if (opt_SLOW_WAR) {
89             struct natstr *natp2;
90             double cost;
91
92             if (!player->god) {
93                 natp2 = themnp;
94                 theirrel = getrel(natp2, us);
95                 if (theirrel <= MOBILIZATION) {
96                     rel = theirrel;
97                     cost = 0;
98                 } else if (us == player->cnum && !update_pending) {
99                     if (mynp->nat_money < War_Cost) {
100                         mpr(us, "You don't have the money!\n");
101                         return RET_FAIL;
102                     }
103                     rel = MOBILIZATION;
104                     cost = War_Cost;
105                 } else {        /* nreport is forcing us to decl war */
106                     return RET_FAIL;
107                 }
108                 if (rel >= oldrel) {
109                     if (us == player->cnum && !update_pending)
110                         mpr(us, "No change required for that!\n");
111                     return RET_FAIL;
112                 }
113                 player->dolcost += cost;
114             }
115         }
116         addendum = "Declaration made (give 'em hell).";
117         n_down = N_DECL_WAR;
118     }
119
120     if (addendum && us == player->cnum && !update_pending)
121         pr("%s\n", addendum);
122     mpr(us, "Diplomatic relations with %s %s to \"%s\".\n", themname,
123         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",
127             myname, us, whichway, relates[rel]);
128
129     putrel(mynp, them, rel);
130     putnat(mynp);
131
132     if (!player->god) {
133         if (oldrel == ALLIED)
134             nreport(us, N_DIS_ALLY, them, 1);
135         else if (oldrel < HOSTILE && rel >= HOSTILE)
136             nreport(us, N_DIS_WAR, them, 1);
137         if (rel > oldrel)
138             nreport(us, n_up, them, 1);
139         else
140             nreport(us, n_down, them, 1);
141     }
142     if (opt_HIDDEN)
143         setcont(them, us, FOUND_TELE);
144
145     return RET_OK;
146 }
147
148 int
149 setcont(natid us, natid them, int contact)
150 {
151     struct natstr *np;
152
153     if ((np = getnatp(us)) == 0)
154         return 0;
155     putcontact(np, them, contact);
156     putnat(np);
157     return 1;
158 }
159
160 int
161 setrej(natid us, natid them, int how, int what)
162 {
163     struct natstr *np;
164
165     if ((np = getnatp(us)) == 0)
166         return 0;
167     putreject(np, them, how, what);
168     putnat(np);
169     return 1;
170 }