comparison senddist.c @ 3:5a977ccbc7a9 default tip

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