annotate linda.c @ 56:d578f3f3b0a6

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