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