1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "main.h"
#include "arena.h"
#include "tux.h"
#include "shot.h"
#include "myTimer.h"
#include "item.h"
#include "gun.h"
#include "proto.h"
#include "net_multiplayer.h"
#include "serverSendMsg.h"
#ifndef NO_SOUND
# include "sound.h"
#endif
#ifndef PUBLIC_SERVER
# include "interface.h"
# include "world.h"
#endif
#ifdef PUBLIC_SERVER
# include "publicServer.h"
#endif
static void modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, int *dest_y)
{
assert(dest_x != NULL);
assert(dest_y != NULL);
switch (courser) {
case TUX_UP:
*dest_x = right_y;
*dest_y = -right_x;
break;
case TUX_RIGHT:
*dest_x = right_x;
*dest_y = right_y;
break;
case TUX_LEFT:
*dest_x = -right_x;
*dest_y = right_y;
break;
case TUX_DOWN:
*dest_x = right_y;
*dest_y = right_x;
break;
default:
assert(!_("There is wrong value in course variable!"));
break;
}
}
static void addShotTrivial(tux_t * tux, int x, int y, int px, int py, int gun)
{
int dest_x = 0, dest_y = 0;
int dest_px = 0, dest_py = 0;
shot_t *shot;
modificiationCopuse(tux->position, px, py, &dest_px, &dest_py);
modificiationCopuse(tux->position, x, y, &dest_x, &dest_y);
if (gun == GUN_LASSER)
switch (tux->position) {
case TUX_UP:
dest_y -= GUN_LASSER_HORIZONTAL;
break;
case TUX_RIGHT:
break;
case TUX_LEFT:
dest_x -= GUN_LASSER_HORIZONTAL;
break;
case TUX_DOWN:
break;
}
shot = shot_new(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux->id);
space_add(arena_get_current()->spaceShot, shot);
}
static void addShot(tux_t * tux, int x, int y, int px, int py)
{
int gun;
if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT)
return;
if (tux->gun == GUN_BOMBBALL)
gun = GUN_BOMBBALL;
else if (tux->gun == GUN_LASSER)
gun = GUN_LASSER;
else
gun = GUN_SIMPLE;
if (tux->bonus == BONUS_4X) {
int zal;
int i;
zal = tux->position;
for (i = 0; i < 4; i++) {
switch (i) {
case 0:
tux->position = TUX_UP;
break;
case 1:
tux->position = TUX_RIGHT;
break;
case 2:
tux->position = TUX_LEFT;
break;
case 3:
tux->position = TUX_DOWN;
break;
}
addShotTrivial(tux, x, y, px, py, gun);
}
tux->position = zal;
} else {
addShotTrivial(tux, x, y, px, py, gun);
}
}
static void gun_shotSimpe(tux_t * tux)
{
addShot(tux, 0, 0, +5, 0);
}
static void gun_shotDualSimpe(tux_t * tux)
{
addShot(tux, 0, -10, +6, 0);
addShot(tux, 0, +10, +6, 0);
}
static void gun_shotScatter(tux_t * tux)
{
int i;
for (i = -2; i <= +2; i++)
addShot(tux, 0, 0, +8, i);
}
static void timer_addShotTimer(void *p)
{
tux_t *tux;
int id;
int gun;
id = *((int *) p);
free(p);
tux = space_get_object_id(arena_get_current()->spaceTux, id);
if (tux == NULL)
return;
if (tux->status != TUX_STATUS_ALIVE)
return;
gun = tux->gun;
tux->gun = GUN_SIMPLE;
addShot(tux, 0, 0, +6, 0);
tux->gun = gun;
}
static void gun_shotTommy(tux_t * tux)
{
int i;
for (i = 0; i < 10; i++)
timer_add_task(arena_get_current()->listTimer, TIMER_ONE,
timer_addShotTimer, newInt(tux->id), i * 100);
}
static void timer_addLaserTimer(void *p)
{
tux_t *tux;
int id;
int gun;
id = *((int *) p);
free(p);
tux = space_get_object_id(arena_get_current()->spaceTux, id);
if (tux == NULL)
return;
if (tux->status != TUX_STATUS_ALIVE)
return;
gun = tux->gun;
tux->gun = GUN_LASSER;
addShot(tux, 0, 0, +10, 0);
addShot(tux, +40, 0, +10, 0);
//addShot(tux, +40, 0, +10, 0);
tux->gun = gun;
}
static void gun_shotLasser(tux_t * tux)
{
int i;
for (i = 0; i < 50; i++)
timer_add_task(arena_get_current()->listTimer, TIMER_ONE,
timer_addLaserTimer, newInt(tux->id), i * 10);
}
static void putInGunMine(tux_t * tux)
{
int x, y;
arena_t *arena;
x = tux->x;
y = tux->y;
switch (tux->position) {
case TUX_UP:
y += TUX_HEIGHT;
break;
case TUX_RIGHT:
x -= TUX_WIDTH;
break;
case TUX_LEFT:
x += TUX_WIDTH;
break;
case TUX_DOWN:
y -= TUX_HEIGHT;
break;
}
arena = arena_get_current();
if (arena_is_free_space(arena_get_current(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT)) {
item_t *item;
#ifndef NO_SOUND
sound_play("put_mine", SOUND_GROUP_BASE);
#endif
tux->shot[tux->gun]--;
if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
item = item_new(x, y, ITEM_MINE, tux->id);
if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER)
proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
space_add(arena->spaceItem, item);
}
}
}
static void gun_shotBombball(tux_t * tux)
{
addShot(tux, 0, 0, +10, 0);
}
void gun_shot(tux_t * tux)
{
if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE)
tux->shot[tux->gun]--;
switch (tux->gun) {
case GUN_SIMPLE:
#ifndef NO_SOUND
sound_play("gun_revolver", SOUND_GROUP_BASE);
#endif
gun_shotSimpe(tux);
break;
case GUN_DUAL_SIMPLE:
#ifndef NO_SOUND
sound_play("gun_revolver", SOUND_GROUP_BASE);
#endif
gun_shotDualSimpe(tux);
break;
case GUN_SCATTER:
#ifndef NO_SOUND
sound_play("gun_scatter", SOUND_GROUP_BASE);
#endif
gun_shotScatter(tux);
break;
case GUN_TOMMY:
#ifndef NO_SOUND
sound_play("gun_tommy", SOUND_GROUP_BASE);
#endif
gun_shotTommy(tux);
break;
case GUN_LASSER:
#ifndef NO_SOUND
sound_play("gun_lasser", SOUND_GROUP_BASE);
#endif
gun_shotLasser(tux);
break;
case GUN_BOMBBALL:
gun_shotBombball(tux);
break;
case GUN_MINE:
putInGunMine(tux);
break;
}
}
|