annotate war.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1 /* $Id: war.c,v 1.1.1.1 1997/12/06 05:41:31 darius Exp $ */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
2
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
3 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
4 * war.c
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
5 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
6 #include "copyright.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
7
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
8 #include <stdio.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
9 #include <math.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10 #include <signal.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
11 #include "Wlib.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
12 #include "defs.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
13 #include "struct.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
14 #include "data.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
15 #include "packets.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16 #include "proto.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18 static int newhostile;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20 /* Set up the war window and map it */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
21 static char *feds = "FED - ";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
22 static char *roms = "ROM - ";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
23 static char *klis = "KLI - ";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24 static char *oris = "ORI - ";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25 static char *gos = " Re-program";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26 static char *exs = " Exit - no change";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27 static char *peaces = "Peace";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28 static char *hostiles = "Hostile";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 static char *wars = "War";
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31 /* Prototypes */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32 static void fillwin P((int menunum, char *string, int hostile, int warbits, int team));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33 static void warrefresh P((void));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36 warwindow()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38 W_MapWindow(war);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39 newhostile = me->p_hostile;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 warrefresh();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 static void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44 warrefresh()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
46 fillwin(0, feds, newhostile, me->p_swar, FEDm);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
47 fillwin(1, roms, newhostile, me->p_swar, ROMm);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
48 fillwin(2, klis, newhostile, me->p_swar, KLIm);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 fillwin(3, oris, newhostile, me->p_swar, ORIm);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50 W_WriteText(war, 0, 4, textColor, gos, strlen(gos), 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 W_WriteText(war, 0, 5, textColor, exs, strlen(exs), 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54 static void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55 fillwin(menunum, string, hostile, warbits, teammask)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56 int menunum;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57 char *string;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 int hostile, warbits;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59 int teammask;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 char buf[80];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63 if (teammask & warbits) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 (void) sprintf(buf, " %s%s", string, wars);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65 W_WriteText(war, 0, menunum, rColor, buf, strlen(buf), 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66 } else if (teammask & hostile) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 (void) sprintf(buf, " %s%s", string, hostiles);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68 W_WriteText(war, 0, menunum, yColor, buf, strlen(buf), 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70 (void) sprintf(buf, " %s%s", string, peaces);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71 W_WriteText(war, 0, menunum, gColor, buf, strlen(buf), 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 waraction(data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79 int enemymask;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81 if (data->y == 4) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82 W_UnmapWindow(war);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 sendWarReq(newhostile);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86 if (data->y == 5) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87 W_UnmapWindow(war);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
88 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
89 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
90 enemymask = 1 << data->y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
91
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
92 if (me->p_swar & enemymask) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
93 warning("You are already at war!");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
94 W_Beep();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
95 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
96 if (idx_to_mask(me->p_teami) == enemymask) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
97 warning("It would never work ... your crew would have you in the brig in no time.");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
98 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
99 newhostile ^= enemymask;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
100 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
101 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
102 warrefresh();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
103 }