0
|
1 /*
|
17
|
2 * $Id$
|
0
|
3 */
|
|
4 #include <stdio.h>
|
|
5 #include <stdlib.h>
|
|
6 #include <math.h>
|
46
|
7 #include <arpa/inet.h>
|
0
|
8 #include <libps2.h>
|
|
9 #include <ps2util.h>
|
|
10
|
|
11 #include "car.h"
|
|
12 #include "game.h"
|
|
13 #include "lindaapi.h"
|
44
|
14 #include "linda.h"
|
0
|
15
|
|
16 extern void carNode_append(CarPtr);
|
|
17 extern FILE *main_fp;
|
43
|
18 static int my_id;
|
0
|
19 static CarPtr linda_carlist[CLIENT_MAX+1];
|
|
20 static int linda_seq[CLIENT_MAX+1];
|
|
21
|
61
|
22 static Bool (*sche_func)(int);
|
|
23
|
0
|
24 static void
|
44
|
25 set_header(unsigned int data, char *pkt, int offset)
|
|
26 {
|
|
27 int *ipkt;
|
|
28 int ndata = htonl(data);
|
|
29
|
|
30 ipkt = (int*)pkt;
|
|
31 ipkt[offset/4] = ndata;
|
|
32 }
|
|
33
|
|
34 static unsigned int
|
|
35 get_header(char *pkt, int offset)
|
|
36 {
|
|
37 int *ipkt;
|
|
38 int data;
|
|
39 unsigned int header;
|
|
40
|
|
41 ipkt = (int *)pkt;
|
|
42 data = ipkt[offset/4];
|
|
43 header = (unsigned int)ntohl(data);
|
|
44
|
|
45 return header;
|
|
46 }
|
|
47
|
|
48 static char*
|
|
49 make_packet(unsigned int mode, unsigned int carid,
|
|
50 unsigned int courseid, char *data)
|
|
51 {
|
|
52 char *packet;
|
|
53 unsigned int len = 0;
|
|
54
|
|
55 if (data) len += sizeof(FMATRIX);
|
|
56
|
|
57 packet = (char*)malloc(PKT_HEADER_SIZE+len);
|
|
58
|
|
59 set_header(mode, packet, PKT_MODE_OFFSET);
|
|
60 set_header(carid, packet, PKT_CARID_OFFSET);
|
|
61 set_header(courseid, packet, PKT_COURSEID_OFFSET);
|
|
62
|
|
63 if (data)
|
|
64 memcpy(packet+PKT_DATA_OFFSET, data, len);
|
|
65
|
|
66 return packet;
|
|
67 }
|
|
68
|
|
69
|
|
70 static void
|
|
71 send_packet(unsigned int dest, unsigned int mode, unsigned int car,
|
|
72 unsigned int course, char *data)
|
|
73 {
|
|
74 char *pkt;
|
|
75 int len = PKT_HEADER_SIZE;
|
|
76
|
|
77 if (data) len += sizeof(FMATRIX);
|
|
78
|
|
79 pkt = make_packet(mode, car, course, data);
|
|
80 psx_out(dest, pkt, len);
|
|
81 free(pkt);
|
|
82 }
|
|
83
|
|
84 static void
|
|
85 get_packet(int id, int *flg, int *mode, int *car, int *course, char *data)
|
|
86 {
|
47
|
87 char *reply = NULL;
|
|
88 char *pkt = NULL;
|
44
|
89
|
|
90 reply = psx_reply(linda_seq[id]);
|
|
91 if (reply) {
|
|
92 pkt = reply+LINDA_HEADER_SIZE;
|
|
93
|
46
|
94 if (flg) *flg = 1;
|
|
95 if (mode) *mode = get_header(pkt, PKT_MODE_OFFSET);
|
|
96 if (car) *car = get_header(pkt, PKT_CARID_OFFSET);
|
|
97 if (course) *course = get_header(pkt, PKT_COURSEID_OFFSET);
|
56
|
98 if (data)
|
|
99 memcpy(data, pkt+PKT_DATA_OFFSET, sizeof(FMATRIX));
|
|
100
|
44
|
101 psx_free(reply);
|
|
102 linda_seq[id] = psx_rd(id);
|
|
103 }
|
|
104 }
|
|
105
|
|
106 static void
|
|
107 linda_set_schedule(void *func, int mode)
|
|
108 {
|
|
109 linda_seq[game.play_id] = psx_in(game.play_id);
|
61
|
110 sche_func = func;
|
69
|
111 send_packet(game.play_id, mode, game.car_id, game.course_id, NULL);
|
44
|
112 }
|
|
113
|
|
114 static Bool
|
58
|
115 linda_sche_wait0(int p)
|
44
|
116 {
|
|
117 int i, flg=0;
|
46
|
118 int id = game.play_id;
|
44
|
119 int connect = 1; // 接続済みユーザ数
|
|
120
|
47
|
121 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
122 if (i == id) continue;
|
50
|
123 get_packet(i, &flg, NULL, NULL, NULL, NULL);
|
51
|
124 if (flg == 1) {
|
|
125 connect++;
|
|
126 flg = 0;
|
|
127 }
|
44
|
128 }
|
|
129
|
58
|
130 if (p == 1 && connect == CLIENT_MAX) {
|
44
|
131 linda_set_schedule(linda_sche_wait_ready0, MODE_WAIT_READY);
|
|
132 return TRUE;
|
|
133 } else {
|
|
134 return FALSE;
|
|
135 }
|
|
136
|
|
137 }
|
|
138
|
|
139 static Bool
|
58
|
140 linda_sche_wait1(int p)
|
44
|
141 {
|
|
142 int mode;
|
|
143
|
|
144 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
145
|
|
146 if (mode == MODE_WAIT_READY) {
|
|
147 linda_set_schedule(linda_sche_wait_ready1, MODE_WAIT_READY);
|
|
148 return TRUE;
|
|
149 } else {
|
|
150 return FALSE;
|
|
151 }
|
|
152 }
|
|
153
|
|
154 static Bool
|
58
|
155 linda_sche_wait_ready0(int p)
|
44
|
156 {
|
|
157 int i, flg, mode;
|
46
|
158 int id = game.play_id;
|
44
|
159 int connect = 1;
|
|
160
|
49
|
161 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
162 if (i == id) continue;
|
50
|
163 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
51
|
164 if (i == id) {
|
|
165 flg = 0;
|
|
166 continue;
|
|
167 }
|
|
168 if (flg == 1 && mode == MODE_WAIT_READY) {
|
44
|
169 connect++;
|
51
|
170 flg = 0;
|
|
171 }
|
44
|
172 }
|
|
173
|
58
|
174 if (p == 1 && connect == CLIENT_MAX) {
|
44
|
175 linda_set_schedule(linda_sche_opening0, MODE_OPENING);
|
|
176 return TRUE;
|
|
177 } else {
|
|
178 return FALSE;
|
|
179 }
|
|
180
|
|
181 }
|
|
182
|
46
|
183 static Bool
|
58
|
184 linda_sche_wait_ready1(int p)
|
44
|
185 {
|
|
186 int mode;
|
|
187
|
|
188 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
189
|
|
190 if (mode == MODE_OPENING) {
|
|
191 linda_set_schedule(linda_sche_opening1, MODE_OPENING);
|
|
192 return TRUE;
|
|
193 } else {
|
|
194 return FALSE;
|
|
195 }
|
|
196 }
|
|
197
|
46
|
198 static Bool
|
58
|
199 linda_sche_opening0(int p)
|
44
|
200 {
|
|
201 int i, flg, mode;
|
46
|
202 int id = game.play_id;
|
44
|
203 int connect = 1;
|
|
204
|
49
|
205 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
206 if (i == id) continue;
|
50
|
207 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
51
|
208 if (flg == 1 && mode == MODE_OPENING) {
|
44
|
209 connect++;
|
51
|
210 flg = 0;
|
|
211 }
|
44
|
212 }
|
|
213
|
58
|
214 if (p == 1 && connect == CLIENT_MAX) {
|
44
|
215 linda_set_schedule(linda_sche_select_car0, MODE_SELECT_CAR);
|
|
216 return TRUE;
|
|
217 } else {
|
|
218 return FALSE;
|
|
219 }
|
|
220 }
|
|
221
|
46
|
222 static Bool
|
58
|
223 linda_sche_opening1(int p)
|
44
|
224 {
|
|
225 int mode;
|
|
226
|
|
227 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
228
|
|
229 if (mode == MODE_SELECT_CAR) {
|
|
230 linda_set_schedule(linda_sche_select_car1, MODE_SELECT_CAR);
|
|
231 return TRUE;
|
|
232 } else {
|
|
233 return FALSE;
|
|
234 }
|
|
235 }
|
|
236
|
|
237 static Bool
|
58
|
238 linda_sche_select_car0(int p)
|
44
|
239 {
|
|
240 int i, flg, mode;
|
46
|
241 int id = game.play_id;
|
44
|
242 int connect = 1;
|
|
243
|
49
|
244 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
245 if (i == id) continue;
|
50
|
246 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
51
|
247 if (flg == 1 && mode == MODE_SELECT_CAR) {
|
44
|
248 connect++;
|
51
|
249 flg = 0;
|
|
250 }
|
44
|
251 }
|
|
252
|
58
|
253 if (p == 1 && connect == CLIENT_MAX) {
|
44
|
254 linda_set_schedule(linda_sche_select_course0, MODE_SELECT_COURSE);
|
|
255 return TRUE;
|
|
256 } else {
|
|
257 return FALSE;
|
|
258 }
|
|
259 }
|
|
260
|
|
261 static Bool
|
58
|
262 linda_sche_select_car1(int p)
|
44
|
263 {
|
|
264 int mode;
|
|
265
|
|
266 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
267
|
|
268 if (mode == MODE_SELECT_COURSE) {
|
|
269 linda_set_schedule(linda_sche_select_course1, MODE_SELECT_COURSE);
|
|
270 return TRUE;
|
|
271 } else {
|
|
272 return FALSE;
|
|
273 }
|
|
274 }
|
|
275
|
|
276 static Bool
|
58
|
277 linda_sche_select_course0(int p)
|
44
|
278 {
|
46
|
279 int i;
|
|
280 int flg, mode;
|
50
|
281 int connect = 1;
|
46
|
282 int id = game.play_id;
|
44
|
283 static int course_id = 1;
|
|
284
|
|
285 if (course_id != game.course_id) {
|
|
286 course_id = game.course_id;
|
58
|
287 linda_seq[id] = psx_in(id);
|
|
288 send_packet(id, MODE_SELECT_COURSE, 0, course_id, NULL);
|
50
|
289 return FALSE;
|
44
|
290 }
|
|
291
|
49
|
292 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
293 if (i == id) continue;
|
50
|
294 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
51
|
295 if (flg == 1 && mode == MODE_SELECT_COURSE) {
|
44
|
296 connect++;
|
51
|
297 flg = 0;
|
|
298 }
|
|
299
|
44
|
300 }
|
|
301
|
58
|
302 if (p == 1 && connect == CLIENT_MAX) {
|
68
|
303 linda_set_schedule(linda_sche_ready0, MODE_READY);
|
44
|
304 return TRUE;
|
|
305 } else {
|
|
306 return FALSE;
|
|
307 }
|
|
308 }
|
|
309
|
|
310 static Bool
|
58
|
311 linda_sche_select_course1(int p)
|
44
|
312 {
|
|
313 int mode, course_id;
|
|
314
|
|
315 get_packet(PLAYER_1P, NULL, &mode, NULL, &course_id, NULL);
|
|
316
|
|
317 if (mode == MODE_SELECT_COURSE) {
|
|
318 game.course_id = course_id;
|
|
319 return FALSE;
|
|
320 } else if (mode == MODE_READY) {
|
68
|
321 linda_set_schedule(linda_sche_ready1, MODE_READY);
|
44
|
322 return TRUE;
|
|
323 } else {
|
|
324 return FALSE;
|
|
325 }
|
|
326 }
|
|
327
|
|
328
|
|
329 static Bool
|
68
|
330 linda_sche_ready0(int p)
|
|
331 {
|
|
332 int i, flg, mode;
|
|
333 int id = game.play_id;
|
|
334 int connect = 1;
|
|
335
|
|
336 for (i=1; i<=CLIENT_MAX; i++) {
|
|
337 if (i == id) continue;
|
|
338 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
|
339 if (flg == 1 && mode == MODE_READY) {
|
|
340 connect++;
|
|
341 flg = 0;
|
|
342 }
|
|
343 }
|
|
344
|
|
345 if (p == 1 && connect == CLIENT_MAX) {
|
69
|
346 linda_set_schedule(linda_sche_main_init, MODE_MAIN_INIT);
|
68
|
347 return TRUE;
|
|
348 } else {
|
|
349 return FALSE;
|
|
350 }
|
|
351 }
|
|
352
|
|
353 static Bool
|
|
354 linda_sche_ready1(int p)
|
|
355 {
|
|
356 int mode;
|
|
357
|
|
358 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
359
|
|
360 if (mode == MODE_MAIN_INIT) {
|
70
|
361 linda_set_schedule(linda_sche_main_init, MODE_MAIN_INIT);
|
68
|
362 return TRUE;
|
|
363 } else {
|
|
364 return FALSE;
|
|
365 }
|
|
366 }
|
|
367
|
|
368 static Bool
|
69
|
369 linda_sche_main_init(int p)
|
|
370 {
|
|
371 int i, flg, mode, car_id;
|
|
372 int id = game.play_id;
|
|
373 int connect = 1;
|
|
374 CarPtr car = NULL;
|
|
375
|
|
376 for (i=1; i<=CLIENT_MAX; i++) {
|
|
377 if (i == id) continue;
|
|
378 get_packet(i, &flg, &mode, &car_id, NULL, NULL);
|
|
379
|
|
380 if (flg == 1 && mode == MODE_MAIN_INIT) {
|
|
381 if (linda_carlist[i] == NULL) {
|
|
382 car = car_init(car_id);
|
|
383 carNode_append(car);
|
|
384 linda_carlist[i] = car;
|
|
385 }
|
|
386 connect++;
|
|
387 flg = 0;
|
|
388 }
|
|
389 }
|
|
390
|
|
391 if (p == 1 && connect == CLIENT_MAX) {
|
|
392 if (id == PLAYER_1P)
|
|
393 linda_set_schedule(linda_sche_main_ready0, MODE_MAIN_READY);
|
|
394 else
|
|
395 linda_set_schedule(linda_sche_main_ready1, MODE_MAIN_READY);
|
|
396 return TRUE;
|
|
397 } else {
|
|
398 return FALSE;
|
|
399 }
|
|
400 }
|
|
401
|
|
402
|
|
403 static Bool
|
|
404 linda_sche_main_ready0(int p)
|
44
|
405 {
|
67
|
406 int i, flg, mode;
|
|
407 int id = game.play_id;
|
|
408 int connect = 1;
|
|
409
|
|
410 for (i=1; i<=CLIENT_MAX; i++) {
|
|
411 if (i == id) continue;
|
|
412 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
69
|
413 if (flg == 1 && mode == MODE_MAIN_READY) {
|
67
|
414 connect++;
|
|
415 flg = 0;
|
|
416 }
|
|
417 }
|
|
418
|
|
419 if (p == 1 && connect == CLIENT_MAX) {
|
74
|
420 linda_set_schedule(linda_sche_main, MODE_MAIN);
|
67
|
421 return TRUE;
|
|
422 } else {
|
|
423 return FALSE;
|
|
424 }
|
44
|
425 }
|
|
426
|
|
427 static Bool
|
69
|
428 linda_sche_main_ready1(int p)
|
44
|
429 {
|
67
|
430 int mode;
|
|
431
|
|
432 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
433
|
|
434 if (mode == MODE_MAIN) {
|
74
|
435 linda_set_schedule(linda_sche_main, MODE_MAIN);
|
67
|
436 return TRUE;
|
|
437 } else {
|
|
438 return FALSE;
|
|
439 }
|
52
|
440 }
|
|
441
|
|
442 static Bool
|
74
|
443 linda_sche_main(int p)
|
|
444 {
|
|
445 int i, flg, mode;
|
|
446 int id = game.play_id;
|
|
447 int connect = 1;
|
|
448 FMATRIX po;
|
|
449 CarPtr mycar = game.jiki;
|
|
450 CarPtr enemy = NULL;
|
|
451 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, (char*)po);
|
|
452
|
|
453 for (i=1; i<=CLIENT_MAX; i++) {
|
|
454 ps2_vu0_unit_matrix(po);
|
|
455
|
|
456 if (i == id) {
|
|
457 ps2_vu0_copy_matrix(po, mycar->body->transfer);
|
|
458 ps2_vu0_copy_vector(po[3], mycar->location);
|
|
459
|
|
460 linda_seq[i] = psx_in(i);
|
|
461 send_packet(i, MODE_MAIN, 0, 0, (char*)po);
|
|
462 } else {
|
|
463 enemy = linda_carlist[i];
|
|
464 get_packet(i, NULL, &mode, NULL, NULL, (char*)po);
|
|
465 if (mode == MODE_MAIN) {
|
|
466 ps2_vu0_copy_matrix(enemy->body->transfer, po);
|
|
467 enemy->body->transfer[3][0] -= game.jiki->location[0];
|
|
468 enemy->body->transfer[3][1] -= game.jiki->location[1];
|
|
469 enemy->body->transfer[3][2] -= game.jiki->location[2];
|
|
470 enemy->body->transfer[3][3] = 1;
|
|
471 }
|
|
472 }
|
|
473 }
|
|
474 return FALSE;
|
|
475 }
|
|
476
|
|
477 static Bool
|
58
|
478 linda_sche_main0(int p)
|
52
|
479 {
|
53
|
480 FMATRIX data;
|
|
481
|
66
|
482 ps2_vu0_unit_matrix(data);
|
|
483 ps2_vu0_copy_matrix(data, game.jiki->body->transfer);
|
|
484 ps2_vu0_copy_vector(data[3], game.jiki->location);
|
58
|
485
|
66
|
486 linda_seq[game.play_id] = psx_in(game.play_id);
|
69
|
487 send_packet(game.play_id, MODE_MAIN, 0, 0, (char*)data);
|
66
|
488
|
69
|
489 return FALSE;
|
52
|
490 }
|
|
491
|
|
492 static Bool
|
58
|
493 linda_sche_main1(int p)
|
52
|
494 {
|
|
495 int mode;
|
|
496 FMATRIX po;
|
73
|
497 CarPtr enemy = linda_carlist[PLAYER_1P];
|
52
|
498 ps2_vu0_unit_matrix(po);
|
55
|
499
|
56
|
500 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, (char*)po);
|
52
|
501
|
|
502 if (mode == MODE_MAIN) {
|
73
|
503 ps2_vu0_copy_matrix(enemy->body->transfer, po);
|
|
504 enemy->body->transfer[3][0] -= game.jiki->location[0];
|
|
505 enemy->body->transfer[3][1] -= game.jiki->location[1];
|
|
506 enemy->body->transfer[3][2] -= game.jiki->location[2];
|
|
507 enemy->body->transfer[3][3] = 1;
|
52
|
508 }
|
|
509
|
44
|
510 return FALSE;
|
|
511 }
|
|
512
|
61
|
513 Bool
|
|
514 linda_update(int p)
|
|
515 {
|
|
516 return sche_func(p);
|
|
517 }
|
|
518
|
44
|
519 #if 0
|
|
520 static void
|
0
|
521 linda_enemy_update(int id, CarPtr enemy, CarInfoPtr tpl)
|
|
522 {
|
|
523 int i,j;
|
|
524
|
|
525 if (id == 1 || tpl->state == GAME_GOAL) {
|
|
526 common_state = tpl->state;
|
|
527 game.course_id = tpl->course_id;
|
|
528 }
|
|
529
|
|
530 if (enemy && (common_state == GAME_MAIN || common_state == GAME_GOAL)) {
|
|
531 for (i=0; i<4; i++) {
|
|
532 for (j=0; j<4; j++) {
|
|
533 enemy->body->transfer[i][j] = tpl->position[i][j];
|
|
534 }
|
|
535 }
|
|
536
|
|
537 /* 敵は相対位置で */
|
|
538 enemy->body->transfer[3][0] -= game.jiki->location[0];
|
|
539 enemy->body->transfer[3][1] -= game.jiki->location[1];
|
|
540 enemy->body->transfer[3][2] -= game.jiki->location[2];
|
|
541 enemy->body->transfer[3][3] = 1;
|
|
542 }
|
|
543 }
|
|
544
|
|
545 /*
|
|
546 * 位置が同じなら1を返す。
|
|
547 * もっと良い比較方法があるんでは...
|
|
548 */
|
|
549 static int
|
|
550 linda_jiki_compareLocation()
|
|
551 {
|
|
552 float x,y,z;
|
|
553 double d;
|
|
554
|
|
555 if (common_state == GAME_MAIN || common_state == GAME_GOAL) {
|
|
556 x = jiki.position[3][0] - game.jiki->location[0];
|
|
557 y = jiki.position[3][1] - game.jiki->location[1];
|
|
558 z = jiki.position[3][2] - game.jiki->location[2];
|
|
559 d = sqrt(x*x+y*y+z*z);
|
|
560
|
|
561 if (d < 1.0) {
|
|
562 return 1;
|
|
563 } else {
|
|
564 return 0;
|
|
565 }
|
|
566 } else {
|
|
567 return 1;
|
|
568 }
|
|
569 }
|
|
570
|
44
|
571
|
0
|
572 /*
|
|
573 * 自機情報が更新されていなければ
|
|
574 * 0を返す(psx_outしない)
|
|
575 */
|
|
576 static int
|
|
577 linda_jiki_compare()
|
|
578 {
|
|
579 if ((jiki.car_id == game.car_id) &&
|
|
580 (jiki.course_id == game.course_id) &&
|
|
581 (jiki.create_flg == ((game.jiki) ? 1:0)) &&
|
|
582 (jiki.state == common_state) &&
|
|
583 (linda_jiki_compareLocation())) {
|
|
584 return 0;
|
|
585 } else {
|
|
586 return 1;
|
|
587 }
|
|
588 }
|
|
589
|
|
590 static void
|
|
591 linda_jiki_update()
|
|
592 {
|
|
593 int i,j;
|
44
|
594
|
0
|
595
|
|
596 jiki.car_id = game.car_id;
|
|
597 jiki.course_id = game.course_id;
|
|
598 jiki.create_flg = (game.jiki) ? 1 : 0;
|
|
599 jiki.state = common_state;
|
|
600
|
|
601 if (common_state == GAME_MAIN || common_state == GAME_GOAL) {
|
|
602 for (i=0; i<3; i++) {
|
|
603 for (j=0; j<4; j++) {
|
|
604 jiki.position[i][j]
|
|
605 = game.jiki->body->transfer[i][j];
|
|
606 }
|
|
607 }
|
|
608 jiki.position[3][0] = game.jiki->location[0];
|
|
609 jiki.position[3][1] = game.jiki->location[1];
|
|
610 jiki.position[3][2] = game.jiki->location[2];
|
|
611 jiki.position[3][3] = 1;
|
|
612 }
|
|
613 }
|
|
614
|
|
615 void
|
|
616 linda_update()
|
|
617 {
|
|
618 int i;
|
|
619 int barrier = 1; // バリア同期(?)用
|
|
620 int connect = 1;
|
44
|
621 int mode, id, flg;
|
0
|
622 char* reply;
|
44
|
623 char* pkt;
|
0
|
624 CarPtr car = NULL;
|
|
625
|
|
626 for (i=1; i<=CLIENT_MAX; i++) {
|
|
627 reply = psx_reply(linda_seq[i]);
|
|
628 if (reply) {
|
44
|
629 pkt = reply+LINDA_HEADER_SIZE;
|
|
630 mode = get_header(pkt, PKT_MODE_OFFSET);
|
|
631 id = get_header(pkt, PKT_ID_OFFSET);
|
|
632 flg = get_header(pkt, PKT_FLG_OFFSET);
|
|
633
|
0
|
634 if (i != game.play_id) {
|
|
635 connect++;
|
|
636
|
|
637 car = linda_carlist[i];
|
|
638 if (common_state == GAME_MAIN && !car && p->create_flg == 1) {
|
|
639 car = car_init(p->car_id);
|
|
640 carNode_append(car);
|
|
641 linda_carlist[i] = car;
|
|
642 }
|
|
643 linda_enemy_update(i, car, p);
|
|
644 if (common_state == p->state) {
|
|
645 barrier++;
|
|
646 }
|
|
647 }
|
|
648 psx_free(reply);
|
|
649 linda_seq[i] = psx_rd(i);
|
|
650 }
|
|
651 }
|
|
652
|
|
653 if (connect == CLIENT_MAX) {
|
|
654 if (game.state == GAME_WAIT) {
|
|
655 gFont_SetString("CONNECT OK!!", 170, 300);
|
|
656 if (game.play_id == 1)
|
|
657 gFont_SetString(" PUSH START ", 170, 400);
|
|
658 }
|
|
659
|
|
660 // ごちゃごちゃしてる...
|
|
661 // なんか無駄な処理がありそうだ
|
|
662 if (game.play_id == 1) {
|
|
663 // 全員のフラグ成立
|
|
664 if (common_state == GAME_GOAL) {
|
|
665 if (game.state == GAME_FINISH) {
|
|
666 common_state = game.state;
|
|
667 } else {
|
|
668 game.state = common_state;
|
|
669 }
|
|
670 } else if (barrier == CLIENT_MAX) {
|
|
671 common_state = game.state;
|
|
672 } else {
|
|
673 game.state = common_state;
|
|
674 }
|
|
675 } else {
|
|
676 if (game.state == GAME_GOAL) {
|
|
677 if (common_state != GAME_FINISH) {
|
|
678 common_state = game.state;
|
|
679 } else {
|
|
680 game.state = common_state;
|
|
681 }
|
|
682 } else {
|
|
683 game.state = common_state;
|
|
684 }
|
|
685 }
|
|
686 } else {
|
|
687 if (game.state == GAME_WAIT) {
|
|
688 gFont_SetString("WAITING...", 200, 100);
|
|
689 }
|
|
690 game.state = common_state;
|
|
691 }
|
|
692
|
|
693 if (linda_jiki_compare()) {
|
|
694 #ifdef DEBUG
|
|
695 // どのタイミングでoutされてるか見る
|
|
696 // 必要なときだけoutしないと重いですね当然だけど
|
|
697 //fprintf(main_fp, "psx_out() jiki\n");
|
|
698 #endif
|
|
699 linda_jiki_update();
|
|
700 // 無理矢理
|
|
701 // 古いものを消すだけなんだけど
|
|
702 // 正しいやり方が他に有るのかな?
|
|
703 // 実行し続けてると最終的に激重になるので
|
|
704 // ここら辺に問題が有るのだろうか。
|
|
705 // psx_free(psx_reply(psx_in(game.play_id)));
|
|
706 linda_seq[my_id]=psx_in(game.play_id);
|
|
707 psx_out(game.play_id, (char*)&jiki, sizeof(CarInfo));
|
|
708 }
|
|
709 }
|
44
|
710 #endif
|
0
|
711
|
|
712 static int
|
|
713 get_id()
|
|
714 {
|
|
715 unsigned char * reply;
|
|
716 int seq;
|
|
717 int id;
|
|
718
|
|
719 //ユーザIDが格納されているTUPLE SpaceのIDへアクセス
|
|
720 seq = psx_in(LINDA_ASK_ID);
|
|
721
|
|
722 // IDが取得できるまでループ
|
|
723 while((reply = psx_reply(seq)) == 0) psx_sync_n();
|
|
724
|
|
725 id = atoi(reply+LINDA_HEADER_SIZE);
|
|
726 psx_free(reply);
|
|
727 return id;
|
|
728 }
|
|
729
|
|
730 void
|
43
|
731 linda_env_init()
|
0
|
732 {
|
43
|
733 int i;
|
0
|
734
|
|
735 for (i=0; i<CLIENT_MAX+1; i++) {
|
|
736 linda_carlist[i] = NULL;
|
|
737 }
|
43
|
738
|
0
|
739 }
|
|
740
|
|
741
|
|
742
|
|
743 int
|
|
744 linda_init()
|
|
745 {
|
|
746 int i;
|
|
747
|
|
748 start_linda(LINDA_HOST);
|
|
749 my_id = get_id();
|
|
750
|
|
751 for (i=1; i<=CLIENT_MAX; i++) {
|
|
752 if (i == my_id) {
|
44
|
753 send_packet(i, MODE_WAIT, i, 0, NULL);
|
0
|
754 }
|
|
755 linda_seq[i] = psx_rd(i);
|
|
756 }
|
|
757 psx_sync_n();
|
|
758
|
48
|
759 if (my_id == PLAYER_1P) {
|
63
|
760 sche_func = &linda_sche_wait0;
|
48
|
761 send_packet(game.play_id, MODE_WAIT, 1, 1, NULL);
|
|
762 } else {
|
63
|
763 sche_func = &linda_sche_wait1;
|
48
|
764 send_packet(game.play_id, MODE_WAIT, 1, 1, NULL);
|
|
765 }
|
0
|
766 return my_id;
|
|
767 }
|