1 | /* |
1 | /* |
2 | * static char *rcsid_move_c = |
2 | * static char *rcsid_move_c = |
3 | * "$Id: move.c,v 1.2 2006/02/03 07:25:25 root Exp $"; |
3 | * "$Id: move.c,v 1.5 2006/03/20 23:58:15 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
29 | #include <global.h> |
29 | #include <global.h> |
30 | #ifndef __CEXTRACT__ |
30 | #ifndef __CEXTRACT__ |
31 | #include <sproto.h> |
31 | #include <sproto.h> |
32 | #endif |
32 | #endif |
33 | |
33 | |
|
|
34 | #ifdef COZY_SERVER |
|
|
35 | // use a ptotoype |
34 | extern int same_party (partylist *a, partylist *b); |
36 | extern int same_party (partylist *a, partylist *b); |
|
|
37 | #endif |
35 | |
38 | |
36 | /* |
39 | /* |
37 | * move_object() tries to move object op in the direction "dir". |
40 | * move_object() tries to move object op in the direction "dir". |
38 | * If it fails (something blocks the passage), it returns 0, |
41 | * If it fails (something blocks the passage), it returns 0, |
39 | * otherwise 1. |
42 | * otherwise 1. |
… | |
… | |
125 | /* we already have newx, newy, and m, so lets use them. |
128 | /* we already have newx, newy, and m, so lets use them. |
126 | * In addition, this fixes potential crashes, because multipart object was |
129 | * In addition, this fixes potential crashes, because multipart object was |
127 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
130 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
128 | */ |
131 | */ |
129 | for(tmp = op; tmp != NULL; tmp = tmp->more) { |
132 | for(tmp = op; tmp != NULL; tmp = tmp->more) { |
130 | tmp->x = newx + tmp->arch->clone.x; |
133 | tmp->x += freearr_x[dir]; |
131 | tmp->y = newy + tmp->arch->clone.y; |
134 | tmp->y += freearr_y[dir]; |
132 | tmp->map = m; |
135 | tmp->map = get_map_from_coord(tmp->map, &tmp->x, &tmp->y); |
133 | } |
136 | } |
134 | |
137 | |
135 | /* insert_ob_in_map will deal with any tiling issues */ |
138 | /* insert_ob_in_map will deal with any tiling issues */ |
136 | insert_ob_in_map(op, m, originator,0); |
139 | insert_ob_in_map(op, m, originator,0); |
137 | |
140 | |
138 | /* Hmmm. Should be possible for multispace players now */ |
141 | /* Hmmm. Should be possible for multispace players now */ |
139 | if (op->type==PLAYER) { |
142 | if (op->type==PLAYER) { |
140 | esrv_map_scroll(&op->contr->socket, freearr_x[dir],freearr_y[dir]); |
143 | esrv_map_scroll(&op->contr->socket, freearr_x[dir],freearr_y[dir]); |
141 | op->contr->socket.update_look=1; |
144 | op->contr->socket.update_look=1; |
142 | op->contr->socket.look_position=0; |
145 | op->contr->socket.look_position=0; |
|
|
146 | } |
|
|
147 | else if (op->type == TRANSPORT) { |
|
|
148 | object *pl; |
|
|
149 | |
|
|
150 | for (pl=op->inv; pl; pl=pl->below) { |
|
|
151 | if (pl->type == PLAYER) { |
|
|
152 | pl->contr->do_los=1; |
|
|
153 | pl->map = op->map; |
|
|
154 | pl->x = op->x; |
|
|
155 | pl->y = op->y; |
|
|
156 | esrv_map_scroll(&pl->contr->socket, freearr_x[dir],freearr_y[dir]); |
|
|
157 | pl->contr->socket.update_look=1; |
|
|
158 | pl->contr->socket.look_position=0; |
|
|
159 | } |
|
|
160 | } |
143 | } |
161 | } |
144 | |
162 | |
145 | return 1; /* this shouldn't be reached */ |
163 | return 1; /* this shouldn't be reached */ |
146 | } |
164 | } |
147 | |
165 | |
… | |
… | |
196 | * be used close to each other and not have the player put to the |
214 | * be used close to each other and not have the player put to the |
197 | * one of another type. |
215 | * one of another type. |
198 | */ |
216 | */ |
199 | int teleport (object *teleporter, uint8 tele_type, object *user) |
217 | int teleport (object *teleporter, uint8 tele_type, object *user) |
200 | { |
218 | { |
201 | object *altern[120]; /* Better use c/malloc here in the future */ |
219 | object *altern; |
202 | int i,j,k,nrofalt=0; |
220 | int i,j,k,nrofalt=0; |
203 | object *other_teleporter, *tmp; |
221 | object *other_teleporter, *tmp; |
204 | mapstruct *m; |
222 | mapstruct *m; |
205 | sint16 sx, sy; |
223 | sint16 sx, sy; |
206 | |
224 | |
… | |
… | |
224 | |
242 | |
225 | while (other_teleporter) { |
243 | while (other_teleporter) { |
226 | if (other_teleporter->type == tele_type) break; |
244 | if (other_teleporter->type == tele_type) break; |
227 | other_teleporter = other_teleporter->above; |
245 | other_teleporter = other_teleporter->above; |
228 | } |
246 | } |
229 | if (other_teleporter) |
247 | if (other_teleporter && !(RANDOM() % ++nrofalt)) |
230 | altern[nrofalt++]=other_teleporter; |
248 | altern = other_teleporter; |
231 | } |
249 | } |
232 | |
250 | |
233 | if(!nrofalt) { |
251 | if(!nrofalt) { |
234 | LOG(llevError,"No alternative teleporters around!\n"); |
252 | LOG(llevError,"No alternative teleporters around!\n"); |
235 | return 0; |
253 | return 0; |
236 | } |
254 | } |
237 | |
255 | |
238 | other_teleporter=altern[RANDOM()%nrofalt]; |
256 | other_teleporter=altern; |
239 | k=find_free_spot(user,other_teleporter->map, |
257 | k=find_free_spot(user,other_teleporter->map, |
240 | other_teleporter->x,other_teleporter->y,1,9); |
258 | other_teleporter->x,other_teleporter->y,1,9); |
241 | |
259 | |
242 | /* if k==-1, unable to find a free spot. If this is shop |
260 | /* if k==-1, unable to find a free spot. If this is shop |
243 | * mat that the player is using, find someplace to move |
261 | * mat that the player is using, find someplace to move |
… | |
… | |
398 | CLEAR_FLAG(who,FLAG_SLEEP); |
416 | CLEAR_FLAG(who,FLAG_SLEEP); |
399 | |
417 | |
400 | /* player change place with his pets or summoned creature */ |
418 | /* player change place with his pets or summoned creature */ |
401 | /* TODO: allow multi arch pushing. Can't be very difficult */ |
419 | /* TODO: allow multi arch pushing. Can't be very difficult */ |
402 | if (who->more == NULL |
420 | if (who->more == NULL |
|
|
421 | #ifdef COZY_SERVER |
403 | && |
422 | && |
404 | ( |
423 | ( |
405 | (owner && owner->contr && pusher->contr |
424 | (owner && owner->contr && pusher->contr |
406 | && same_party (owner->contr->party, pusher->contr->party)) |
425 | && same_party (owner->contr->party, pusher->contr->party)) |
407 | || owner == pusher |
426 | || owner == pusher |
408 | ) |
427 | ) |
|
|
428 | #else |
|
|
429 | && owner == pusher |
|
|
430 | #endif |
409 | ) { |
431 | ) { |
410 | int temp; |
432 | int temp; |
411 | mapstruct *m; |
433 | mapstruct *m; |
412 | |
434 | |
413 | remove_ob(who); |
435 | remove_ob(who); |