annotate senddist.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: senddist.c,v 1.1.1.1 1997/12/06 05:41:30 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 * distress.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 <signal.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10 #include <ctype.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 "gameconf.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18 /* #$!@$#% length of address field of messages */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19 #define ADDRLEN 10
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
21
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
22 /* this loads all sorts of useful data into a distress struct.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
23 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24 struct distress *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25 loaddistress(i, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26 enum dist_type i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 struct distress *dist;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30 struct obtype *gettarget(), *gettarget2(), *target;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32 dist = (struct distress *) malloc(sizeof(struct distress));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34 dist->sender = me->p_no;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 dist->dam = (100 * me->p_damage) / me->p_ship->s_maxdamage;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36 dist->shld = (100 * me->p_shield) / me->p_ship->s_maxshield;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37 dist->arms = me->p_armies;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38 dist->fuelp = (100 * me->p_fuel) / me->p_ship->s_maxfuel;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39 dist->wtmp = (100 * me->p_wtemp) / me->p_ship->s_maxwpntemp;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 dist->etmp = (100 * me->p_etemp) / me->p_ship->s_maxegntemp;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 /* so.. call me paranoid -jmn */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42 dist->sts = (me->p_flags & 0xff) | 0x80;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 dist->wtmpflag = ((me->p_flags & PFWEP) > 0) ? 1 : 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44 dist->etempflag = ((me->p_flags & PFENG) > 0) ? 1 : 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45 dist->cloakflag = ((me->p_flags & PFCLOAK) > 0) ? 1 : 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
46
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
47 dist->distype = i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
48 if (dist->distype > generic || dist->distype < take)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 dist->distype = generic;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 target = gettarget(0, me->p_x, me->p_y, TARG_PLANET);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52 dist->close_pl = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54 target = gettarget(data->Window, data->x, data->y, TARG_PLANET);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55 dist->tclose_pl = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57 target = gettarget(0, me->p_x, me->p_y, TARG_PLAYER | TARG_ENEMY);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 dist->close_en = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60 target = gettarget(data->Window, data->x, data->y, TARG_PLAYER | TARG_ENEMY);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 dist->tclose_en = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63 target = gettarget(0, me->p_x, me->p_y, TARG_PLAYER | TARG_FRIENDLY);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 dist->close_fr = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66 target = gettarget(data->Window, data->x, data->y, TARG_PLAYER | TARG_FRIENDLY);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 dist->tclose_fr = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 target = gettarget(0, me->p_x, me->p_y, TARG_PLAYER);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70 dist->close_j = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72 target = gettarget(data->Window, data->x, data->y, TARG_PLAYER);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 dist->tclose_j = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 /* lets make sure these aren't something stupid */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 dist->cclist[0] = 0x80;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77 dist->preappend[0] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78 dist->macroflag = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80 return (dist);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 /* Coordinating function for _SENDING_ a RCD */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 /* Send an rcd signal out to everyone. */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87 rcd(i, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
88 enum dist_type i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
89 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
90 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
91 char ebuf[200];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
92 struct distress *dist;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
93 char cry[MSG_LEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
94 char *info, *getaddr2();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
95 int len;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
96 int recip;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
97 int group;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
98
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
99
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
100 group = MTEAM;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
101 recip = idx_to_mask(me->p_teami);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
102
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
103 dist = loaddistress(i, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
104
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
105 if (F_gen_distress) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
106 /* send a generic distress message */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
107 Dist2Mesg(dist, ebuf);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
108 pmessage(ebuf, recip, group | MDISTR);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
109 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
110 len = makedistress(dist, cry, distmacro[dist->distype].macro);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
111
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
112 if (len > 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
113 /* klude alert */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
114 info = cry;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
115 if (strncmp(getaddr2(MTEAM, mask_to_idx(recip)), cry, 8) == 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
116 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
117 this means we should _strip_ the leading bit because it's
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
118 redundant
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
119 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
120 info = cry + 9;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
121 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
122 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
123 pmessage(info, recip, group);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
124 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
125
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
126 free(dist);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
127 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
128
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
129 /* the primary subroutine for newmacro, converts the strange and wonderful
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
130 ** newmacro syntax into an actual message.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
131 ** This is about as inefficient as they come, but how often is the player
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
132 ** going to send a macro??
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
133 ** 6/3/93 - jn
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
134 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
135 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
136 pmacro(mnum, who, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
137 int mnum;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
138 char who;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
139 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
140 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
141 char addr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
142 int group, len, recip;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
143 char cry[MSG_LEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
144 char *pm;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
145 struct distress *dist;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
146
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
147
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
148 if (!F_UseNewMacro)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
149 return 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
150
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
151 /* get recipient and group */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
152 if ((who == 't') || (who == 'T'))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
153 addr = teaminfo[me->p_teami].letter;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
154 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
155 addr = who;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
156
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
157 group = getgroup(addr, &recip);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
158
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
159 if (!group) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
160 printf("Bad group!\n");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
161 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
162 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
163 pm = macrotable[mnum]->string;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
164
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
165 dist = loaddistress(0, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
166
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
167 len = makedistress(dist, cry, pm);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
168
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
169 if (len > 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
170 pmessage(cry, recip, group);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
171
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
172 free(dist);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
173 return 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
174 }