]> 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-2018, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  rej.c: Various relations setting routines
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1994
31  *     Markus Armbruster, 2005-2016
32  */
33
34 #include <config.h>
35
36 #include "nat.h"
37 #include "news.h"
38 #include "optlist.h"
39 #include "player.h"
40 #include "prototypes.h"
41 #include "update.h"
42
43 void
44 setrel(natid us, natid them, enum relations rel)
45 {
46     struct relatstr *relp = getrelatp(us);
47     struct natstr *mynp = getnatp(us);
48     enum relations oldrel;
49     char *whichway;
50     int n_up = 0;
51     int n_down = 0;
52     char *addendum = NULL;
53
54     if (CANT_HAPPEN(rel < AT_WAR))
55         rel = AT_WAR;
56     if (CANT_HAPPEN(rel > ALLIED))
57         rel = ALLIED;
58     if (CANT_HAPPEN(!relp || !mynp))
59         return;
60     if (us == them)
61         return;
62     oldrel = relations_with(us, them);
63     if (oldrel == rel)
64         return;
65     if (rel > oldrel)
66         whichway = "upgraded";
67     else
68         whichway = "downgraded";
69     if (rel == ALLIED) {
70         addendum = "Congratulations!";
71         n_up = N_DECL_ALLY;
72     } else if (rel == FRIENDLY) {
73         n_up = N_UP_FRIENDLY;
74         n_down = N_DOWN_FRIENDLY;
75     } else if (rel == NEUTRAL) {
76         n_up = N_UP_NEUTRAL;
77         n_down = N_DOWN_NEUTRAL;
78     } else if (rel == HOSTILE) {
79         addendum = "Another cold war...";
80         n_up = N_UP_HOSTILE;
81         n_down = N_DOWN_HOSTILE;
82     } else if (rel < HOSTILE) {
83         addendum = "Declaration made (give 'em hell).";
84         n_down = N_DECL_WAR;
85     }
86
87     if (addendum && us == player->cnum && !update_running)
88         pr("%s\n", addendum);
89     mpr(us, "Diplomatic relations with %s %s to \"%s\".\n",
90         cname(them), whichway, relations_string(rel));
91     if (nat_accepts(them, us, REJ_TELE))
92         mpr(them,
93             "Country %s has %s their relations with you to \"%s\"!\n",
94             prnat(mynp), whichway, relations_string(rel));
95
96     relp->rel_relate[them] = rel;
97     putrelat(relp);
98
99     if (!player->god) {
100         if (oldrel == ALLIED)
101             nreport(us, N_DIS_ALLY, them, 1);
102         else if (oldrel < HOSTILE && rel >= HOSTILE)
103             nreport(us, N_DIS_WAR, them, 1);
104         if (rel > oldrel)
105             nreport(us, n_up, them, 1);
106         else
107             nreport(us, n_down, them, 1);
108     }
109     if (opt_HIDDEN)
110         setcont(them, us, FOUND_TELE);
111 }
112
113 void
114 setcont(natid us, natid them, int contact)
115 {
116     struct contactstr *conp = getcontactp(us);
117
118     if (CANT_HAPPEN(!conp))
119         return;
120
121     if (CANT_HAPPEN(contact < 0))
122         contact = 0;
123     if (CANT_HAPPEN(contact > 255))
124         contact = 255;
125
126     if (!opt_LOSE_CONTACT)
127         contact = !!contact;
128     if (conp->con_contact[them] < contact) {
129         conp->con_contact[them] = contact;
130         putcontact(conp);
131     }
132 }
133
134 void
135 setrej(natid us, natid them, int reject, enum rej_comm what)
136 {
137     struct rejectstr *rejp = getrejectp(us);
138
139     if (CANT_HAPPEN(!rejp))
140         return;
141     if (reject)
142         rejp->rej_rejects[them] |= bit(what);
143     else
144         rejp->rej_rejects[them] &= ~bit(what);
145     putreject(rejp);
146 }