annotate linda.c @ 46:abadcc080667

*** empty log message ***
author gongo
date Wed, 08 Nov 2006 06:10:44 +0000
parents 3b71b39411b1
children d7e0a5c33540
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
1 /*
17
6910aeb52843 *** empty log message ***
gongo
parents: 0
diff changeset
2 * $Id$
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
3 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
4 #include <stdio.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
5 #include <stdlib.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
6 #include <math.h>
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
7 #include <arpa/inet.h>
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
8 #include <libps2.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
9 #include <ps2util.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
10
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
11 #include "car.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
12 #include "game.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
13 #include "lindaapi.h"
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
14 #include "linda.h"
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
15
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
16 extern void carNode_append(CarPtr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
17 extern FILE *main_fp;
43
a1908b83f8fa *** empty log message ***
gongo
parents: 17
diff changeset
18 static int my_id;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
19 static CarPtr linda_carlist[CLIENT_MAX+1];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
20 static int linda_seq[CLIENT_MAX+1];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
21
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
22 static void
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
23 set_header(unsigned int data, char *pkt, int offset)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
24 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
25 int *ipkt;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
26 int ndata = htonl(data);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
27
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
28 ipkt = (int*)pkt;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
29 ipkt[offset/4] = ndata;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
30 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
31
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
32 static unsigned int
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
33 get_header(char *pkt, int offset)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
34 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
35 int *ipkt;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
36 int data;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
37 unsigned int header;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
38
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
39 ipkt = (int *)pkt;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
40 data = ipkt[offset/4];
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
41 header = (unsigned int)ntohl(data);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
42
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
43 return header;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
44 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
45
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
46 static char*
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
47 make_packet(unsigned int mode, unsigned int carid,
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
48 unsigned int courseid, char *data)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
49 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
50 char *packet;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
51 unsigned int len = 0;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
52
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
53 if (data) len += sizeof(FMATRIX);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
54
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
55 packet = (char*)malloc(PKT_HEADER_SIZE+len);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
56
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
57 set_header(mode, packet, PKT_MODE_OFFSET);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
58 set_header(carid, packet, PKT_CARID_OFFSET);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
59 set_header(courseid, packet, PKT_COURSEID_OFFSET);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
60
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
61 if (data)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
62 memcpy(packet+PKT_DATA_OFFSET, data, len);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
63
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
64 return packet;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
65 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
66
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
67
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
68 static void
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
69 send_packet(unsigned int dest, unsigned int mode, unsigned int car,
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
70 unsigned int course, char *data)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
71 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
72 char *pkt;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
73 int len = PKT_HEADER_SIZE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
74
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
75 if (data) len += sizeof(FMATRIX);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
76
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
77 pkt = make_packet(mode, car, course, data);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
78 psx_out(dest, pkt, len);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
79 free(pkt);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
80 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
81
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
82 static void
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
83 get_packet(int id, int *flg, int *mode, int *car, int *course, char *data)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
84 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
85 char *reply, *pkt;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
86
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
87 reply = psx_reply(linda_seq[id]);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
88 if (reply) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
89 pkt = reply+LINDA_HEADER_SIZE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
90
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
91 if (flg) *flg = 1;
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
92 if (mode) *mode = get_header(pkt, PKT_MODE_OFFSET);
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
93 if (car) *car = get_header(pkt, PKT_CARID_OFFSET);
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
94 if (course) *course = get_header(pkt, PKT_COURSEID_OFFSET);
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
95 //if (data) data = get_header(pkt, PKT_DATA_OFFSET);
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
96
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
97 psx_free(reply);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
98 linda_seq[id] = psx_rd(id);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
99 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
100 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
101
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
102 static void
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
103 linda_set_schedule(void *func, int mode)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
104 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
105 linda_seq[game.play_id] = psx_in(game.play_id);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
106 game.linda_exec = func;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
107 send_packet(game.play_id, mode, 1, 1, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
108 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
109
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
110 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
111 linda_sche_wait0()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
112 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
113 int i, flg=0;
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
114 int id = game.play_id;
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
115 int connect = 1; // 接続済みユーザ数
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
116
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
117 for (i=1; i<=CLIENT_MAX+1; i++) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
118 if (i == id) continue;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
119
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
120 get_packet(i, &flg, NULL, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
121
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
122 if (flg == 1) connect++;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
123 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
124
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
125 if (connect == CLIENT_MAX) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
126 linda_set_schedule(linda_sche_wait_ready0, MODE_WAIT_READY);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
127 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
128 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
129 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
130 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
131
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
132 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
133
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
134 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
135 linda_sche_wait1()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
136 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
137 int mode;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
138
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
139 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
140
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
141 if (mode == MODE_WAIT_READY) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
142 linda_set_schedule(linda_sche_wait_ready1, MODE_WAIT_READY);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
143 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
144 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
145 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
146 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
147 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
148
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
149 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
150 linda_sche_wait_ready0()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
151 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
152 int i, flg, mode;
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
153 int id = game.play_id;
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
154 int connect = 1;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
155
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
156 for (i=1; i<=CLIENT_MAX+1; i++) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
157 if (i == id) continue;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
158
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
159 get_packet(i, &flg, &mode, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
160 if (flg == 1 && mode == MODE_WAIT_READY)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
161 connect++;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
162 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
163
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
164 if (connect == CLIENT_MAX) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
165 linda_set_schedule(linda_sche_opening0, MODE_OPENING);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
166 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
167 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
168 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
169 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
170
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
171 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
172
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
173 static Bool
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
174 linda_sche_wait_ready1()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
175 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
176 int mode;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
177
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
178 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
179
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
180 if (mode == MODE_OPENING) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
181 linda_set_schedule(linda_sche_opening1, MODE_OPENING);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
182 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
183 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
184 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
185 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
186 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
187
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
188 static Bool
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
189 linda_sche_opening0()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
190 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
191 int i, flg, mode;
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
192 int id = game.play_id;
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
193 int connect = 1;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
194
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
195 for (i=1; i<=CLIENT_MAX+1; i++) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
196 if (i == id) continue;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
197
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
198 get_packet(i, &flg, &mode, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
199 if (flg == 1 && mode == MODE_OPENING)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
200 connect++;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
201 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
202
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
203 if (connect == CLIENT_MAX) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
204 linda_set_schedule(linda_sche_select_car0, MODE_SELECT_CAR);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
205 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
206 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
207 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
208 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
209 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
210
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
211 static Bool
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
212 linda_sche_opening1()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
213 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
214 int mode;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
215
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
216 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
217
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
218 if (mode == MODE_SELECT_CAR) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
219 linda_set_schedule(linda_sche_select_car1, MODE_SELECT_CAR);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
220 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
221 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
222 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
223 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
224 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
225
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
226 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
227 linda_sche_select_car0()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
228 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
229 int i, flg, mode;
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
230 int id = game.play_id;
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
231 int connect = 1;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
232
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
233 for (i=1; i<=CLIENT_MAX+1; i++) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
234 if (i == id) continue;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
235
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
236 get_packet(i, &flg, &mode, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
237 if (flg == 1 && mode == MODE_SELECT_CAR)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
238 connect++;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
239 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
240
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
241 if (connect == CLIENT_MAX) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
242 linda_set_schedule(linda_sche_select_course0, MODE_SELECT_COURSE);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
243 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
244 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
245 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
246 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
247 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
248
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
249 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
250 linda_sche_select_car1()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
251 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
252 int mode;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
253
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
254 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
255
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
256 if (mode == MODE_SELECT_COURSE) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
257 linda_set_schedule(linda_sche_select_course1, MODE_SELECT_COURSE);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
258 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
259 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
260 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
261 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
262 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
263
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
264 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
265 linda_sche_select_course0()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
266 {
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
267 int i;
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
268 int flg, mode;
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
269 int connect;
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
270 int id = game.play_id;
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
271 static int course_id = 1;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
272
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
273 if (course_id != game.course_id) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
274 course_id = game.course_id;
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
275 send_packet(game.play_id, MODE_SELECT_COURSE, 0, course_id, NULL);
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
276 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
277 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
278
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
279 for (i=1; i<=CLIENT_MAX+1; i++) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
280 if (i == id) continue;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
281
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
282 get_packet(i, &flg, &mode, NULL, NULL, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
283 if (flg == 1 && mode == MODE_SELECT_COURSE)
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
284 connect++;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
285 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
286
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
287 if (connect == CLIENT_MAX) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
288 linda_set_schedule(linda_sche_ready0, MODE_READY);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
289 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
290 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
291 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
292 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
293 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
294
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
295 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
296 linda_sche_select_course1()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
297 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
298 int mode, course_id;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
299
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
300 get_packet(PLAYER_1P, NULL, &mode, NULL, &course_id, NULL);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
301
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
302 if (mode == MODE_SELECT_COURSE) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
303 game.course_id = course_id;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
304 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
305 } else if (mode == MODE_READY) {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
306 linda_set_schedule(linda_sche_ready1, MODE_READY);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
307 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
308 } else {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
309 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
310 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
311 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
312
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
313
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
314 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
315 linda_sche_ready0()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
316 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
317 return TRUE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
318 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
319
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
320 static Bool
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
321 linda_sche_ready1()
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
322 {
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
323 return FALSE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
324 }
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
325
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
326 #if 0
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
327 static void
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
328 linda_enemy_update(int id, CarPtr enemy, CarInfoPtr tpl)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
329 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
330 int i,j;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
331
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
332 if (id == 1 || tpl->state == GAME_GOAL) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
333 common_state = tpl->state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
334 game.course_id = tpl->course_id;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
335 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
336
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
337 if (enemy && (common_state == GAME_MAIN || common_state == GAME_GOAL)) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
338 for (i=0; i<4; i++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
339 for (j=0; j<4; j++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
340 enemy->body->transfer[i][j] = tpl->position[i][j];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
341 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
342 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
343
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
344 /* 敵は相対位置で */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
345 enemy->body->transfer[3][0] -= game.jiki->location[0];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
346 enemy->body->transfer[3][1] -= game.jiki->location[1];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
347 enemy->body->transfer[3][2] -= game.jiki->location[2];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
348 enemy->body->transfer[3][3] = 1;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
349 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
350 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
351
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
352 /*
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
353 * 位置が同じなら1を返す。
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
354 * もっと良い比較方法があるんでは...
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
355 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
356 static int
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
357 linda_jiki_compareLocation()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
358 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
359 float x,y,z;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
360 double d;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
361
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
362 if (common_state == GAME_MAIN || common_state == GAME_GOAL) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
363 x = jiki.position[3][0] - game.jiki->location[0];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
364 y = jiki.position[3][1] - game.jiki->location[1];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
365 z = jiki.position[3][2] - game.jiki->location[2];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
366 d = sqrt(x*x+y*y+z*z);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
367
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
368 if (d < 1.0) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
369 return 1;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
370 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
371 return 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
372 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
373 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
374 return 1;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
375 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
376 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
377
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
378
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
379 /*
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
380 * 自機情報が更新されていなければ
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
381 * 0を返す(psx_outしない)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
382 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
383 static int
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
384 linda_jiki_compare()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
385 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
386 if ((jiki.car_id == game.car_id) &&
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
387 (jiki.course_id == game.course_id) &&
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
388 (jiki.create_flg == ((game.jiki) ? 1:0)) &&
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
389 (jiki.state == common_state) &&
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
390 (linda_jiki_compareLocation())) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
391 return 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
392 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
393 return 1;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
394 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
395 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
396
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
397 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
398 linda_jiki_update()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
399 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
400 int i,j;
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
401
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
402
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
403 jiki.car_id = game.car_id;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
404 jiki.course_id = game.course_id;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
405 jiki.create_flg = (game.jiki) ? 1 : 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
406 jiki.state = common_state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
407
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
408 if (common_state == GAME_MAIN || common_state == GAME_GOAL) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
409 for (i=0; i<3; i++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
410 for (j=0; j<4; j++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
411 jiki.position[i][j]
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
412 = game.jiki->body->transfer[i][j];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
413 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
414 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
415 jiki.position[3][0] = game.jiki->location[0];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
416 jiki.position[3][1] = game.jiki->location[1];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
417 jiki.position[3][2] = game.jiki->location[2];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
418 jiki.position[3][3] = 1;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
419 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
420 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
421
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
422 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
423 linda_update()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
424 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
425 int i;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
426 int barrier = 1; // バリア同期(?)用
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
427 int connect = 1;
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
428 int mode, id, flg;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
429 char* reply;
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
430 char* pkt;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
431 CarPtr car = NULL;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
432
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
433 for (i=1; i<=CLIENT_MAX; i++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
434 reply = psx_reply(linda_seq[i]);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
435 if (reply) {
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
436 pkt = reply+LINDA_HEADER_SIZE;
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
437 mode = get_header(pkt, PKT_MODE_OFFSET);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
438 id = get_header(pkt, PKT_ID_OFFSET);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
439 flg = get_header(pkt, PKT_FLG_OFFSET);
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
440
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
441 if (i != game.play_id) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
442 connect++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
443
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
444 car = linda_carlist[i];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
445 if (common_state == GAME_MAIN && !car && p->create_flg == 1) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
446 car = car_init(p->car_id);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
447 carNode_append(car);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
448 linda_carlist[i] = car;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
449 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
450 linda_enemy_update(i, car, p);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
451 if (common_state == p->state) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
452 barrier++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
453 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
454 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
455 psx_free(reply);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
456 linda_seq[i] = psx_rd(i);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
457 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
458 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
459
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
460 if (connect == CLIENT_MAX) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
461 if (game.state == GAME_WAIT) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
462 gFont_SetString("CONNECT OK!!", 170, 300);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
463 if (game.play_id == 1)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
464 gFont_SetString(" PUSH START ", 170, 400);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
465 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
466
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
467 // ごちゃごちゃしてる...
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
468 // なんか無駄な処理がありそうだ
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
469 if (game.play_id == 1) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
470 // 全員のフラグ成立
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
471 if (common_state == GAME_GOAL) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
472 if (game.state == GAME_FINISH) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
473 common_state = game.state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
474 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
475 game.state = common_state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
476 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
477 } else if (barrier == CLIENT_MAX) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
478 common_state = game.state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
479 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
480 game.state = common_state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
481 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
482 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
483 if (game.state == GAME_GOAL) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
484 if (common_state != GAME_FINISH) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
485 common_state = game.state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
486 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
487 game.state = common_state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
488 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
489 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
490 game.state = common_state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
491 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
492 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
493 } else {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
494 if (game.state == GAME_WAIT) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
495 gFont_SetString("WAITING...", 200, 100);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
496 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
497 game.state = common_state;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
498 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
499
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
500 if (linda_jiki_compare()) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
501 #ifdef DEBUG
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
502 // どのタイミングでoutされてるか見る
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
503 // 必要なときだけoutしないと重いですね当然だけど
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
504 //fprintf(main_fp, "psx_out() jiki\n");
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
505 #endif
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
506 linda_jiki_update();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
507 // 無理矢理
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
508 // 古いものを消すだけなんだけど
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
509 // 正しいやり方が他に有るのかな?
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
510 // 実行し続けてると最終的に激重になるので
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
511 // ここら辺に問題が有るのだろうか。
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
512 // psx_free(psx_reply(psx_in(game.play_id)));
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
513 linda_seq[my_id]=psx_in(game.play_id);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
514 psx_out(game.play_id, (char*)&jiki, sizeof(CarInfo));
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
515 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
516 }
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
517 #endif
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
518
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
519 static int
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
520 get_id()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
521 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
522 unsigned char * reply;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
523 int seq;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
524 int id;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
525
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
526 //ユーザIDが格納されているTUPLE SpaceのIDへアクセス
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
527 seq = psx_in(LINDA_ASK_ID);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
528
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
529 // IDが取得できるまでループ
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
530 while((reply = psx_reply(seq)) == 0) psx_sync_n();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
531
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
532 id = atoi(reply+LINDA_HEADER_SIZE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
533 psx_free(reply);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
534 return id;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
535 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
536
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
537 void
43
a1908b83f8fa *** empty log message ***
gongo
parents: 17
diff changeset
538 linda_env_init()
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
539 {
43
a1908b83f8fa *** empty log message ***
gongo
parents: 17
diff changeset
540 int i;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
541
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
542 for (i=0; i<CLIENT_MAX+1; i++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
543 linda_carlist[i] = NULL;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
544 }
43
a1908b83f8fa *** empty log message ***
gongo
parents: 17
diff changeset
545
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
546 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
547
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
548
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
549
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
550 int
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
551 linda_init()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
552 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
553 int i;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
554
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
555 start_linda(LINDA_HOST);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
556 my_id = get_id();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
557
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
558 for (i=1; i<=CLIENT_MAX; i++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
559 if (i == my_id) {
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
560 send_packet(i, MODE_WAIT, i, 0, NULL);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
561 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
562 linda_seq[i] = psx_rd(i);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
563 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
564 psx_sync_n();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
565
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
566 if (my_id == PLAYER_1P)
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
567 linda_set_schedule(linda_sche_wait0, MODE_WAIT);
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
568 else
46
abadcc080667 *** empty log message ***
gongo
parents: 44
diff changeset
569 linda_set_schedule(linda_sche_wait1, MODE_WAIT);
44
3b71b39411b1 *** empty log message ***
gongo
parents: 43
diff changeset
570
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
571 return my_id;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
572 }