1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_main_c = |
|
|
4 | * "$Id: main.C,v 1.23 2006/09/10 15:59:57 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | #include <global.h> |
24 | #include <global.h> |
31 | #include <object.h> |
25 | #include <object.h> |
32 | #include <tod.h> |
26 | #include <tod.h> |
… | |
… | |
112 | new_draw_info (NDI_UNIQUE, 0, op, "Images and art:"); |
106 | new_draw_info (NDI_UNIQUE, 0, op, "Images and art:"); |
113 | new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner"); |
107 | new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner"); |
114 | new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]"); |
108 | new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]"); |
115 | new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]"); |
109 | new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]"); |
116 | new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]"); |
110 | new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]"); |
117 | new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg [maxmc@telia.com]"); |
111 | new_draw_info (NDI_UNIQUE, 0, op, "MÃ¥rten Woxberg [maxmc@telia.com]"); |
118 | new_draw_info (NDI_UNIQUE, 0, op, "And many more!"); |
112 | new_draw_info (NDI_UNIQUE, 0, op, "And many more!"); |
119 | } |
113 | } |
120 | |
114 | |
121 | void |
115 | void |
122 | info_keys (object *op) |
116 | info_keys (object *op) |
… | |
… | |
164 | * simple case at top - no encryption - makes it easier to read. |
158 | * simple case at top - no encryption - makes it easier to read. |
165 | */ |
159 | */ |
166 | char * |
160 | char * |
167 | crypt_string (char *str, char *salt) |
161 | crypt_string (char *str, char *salt) |
168 | { |
162 | { |
169 | #if defined(WIN32) || (defined(__FreeBSD__) && !defined(HAVE_LIBDES)) |
163 | #if (defined(__FreeBSD__) && !defined(HAVE_LIBDES)) |
170 | return (str); |
164 | return (str); |
171 | #else |
165 | #else |
172 | static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
166 | static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
173 | char s[2]; |
167 | char s[2]; |
174 | |
168 | |
… | |
… | |
197 | * goes someplace. |
191 | * goes someplace. |
198 | */ |
192 | */ |
199 | void |
193 | void |
200 | enter_player_savebed (object *op) |
194 | enter_player_savebed (object *op) |
201 | { |
195 | { |
202 | mapstruct *oldmap = op->map; |
196 | maptile *oldmap = op->map; |
203 | object *tmp; |
197 | object *tmp; |
204 | |
198 | |
205 | tmp = get_object (); |
199 | tmp = get_object (); |
206 | |
200 | |
207 | EXIT_PATH (tmp) = op->contr->savebed_map; |
201 | EXIT_PATH (tmp) = op->contr->savebed_map; |
… | |
… | |
232 | * the counts on the map if needed. |
226 | * the counts on the map if needed. |
233 | */ |
227 | */ |
234 | void |
228 | void |
235 | leave_map (object *op) |
229 | leave_map (object *op) |
236 | { |
230 | { |
237 | mapstruct *oldmap = op->map; |
231 | maptile *oldmap = op->map; |
238 | |
232 | |
239 | remove_ob (op); |
233 | remove_ob (op); |
240 | |
234 | |
241 | if (oldmap) |
235 | if (oldmap) |
242 | { |
236 | { |
243 | if (!op->contr->hidden) |
237 | if (!op->contr->hidden) |
244 | oldmap->players--; |
238 | oldmap->players--; |
|
|
239 | |
245 | if (oldmap->players <= 0) |
240 | if (oldmap->players <= 0) |
246 | { /* can be less than zero due to errors in tracking this */ |
241 | /* can be less than zero due to errors in tracking this */ |
247 | set_map_timeout (oldmap); |
242 | set_map_timeout (oldmap); |
248 | } |
|
|
249 | } |
243 | } |
250 | } |
244 | } |
251 | |
245 | |
252 | /* |
246 | /* |
253 | * enter_map(): Moves the player and pets from current map (if any) to |
247 | * enter_map(): Moves the player and pets from current map (if any) to |
… | |
… | |
255 | * player to - it could be the map he just came from if the load failed for |
249 | * player to - it could be the map he just came from if the load failed for |
256 | * whatever reason. If default map coordinates are to be used, then |
250 | * whatever reason. If default map coordinates are to be used, then |
257 | * the function that calls this should figure them out. |
251 | * the function that calls this should figure them out. |
258 | */ |
252 | */ |
259 | static void |
253 | static void |
260 | enter_map (object *op, mapstruct *newmap, int x, int y) |
254 | enter_map (object *op, maptile *newmap, int x, int y) |
261 | { |
255 | { |
262 | mapstruct *oldmap = op->map; |
256 | maptile *oldmap = op->map; |
263 | |
257 | |
264 | if (out_of_map (newmap, x, y)) |
258 | if (out_of_map (newmap, x, y)) |
265 | { |
259 | { |
266 | LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); |
260 | LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); |
267 | x = MAP_ENTER_X (newmap); |
261 | x = MAP_ENTER_X (newmap); |
… | |
… | |
272 | newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap)); |
266 | newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap)); |
273 | new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); |
267 | new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); |
274 | return; |
268 | return; |
275 | } |
269 | } |
276 | } |
270 | } |
|
|
271 | |
277 | /* try to find a spot for the player */ |
272 | /* try to find a spot for the player */ |
278 | if (ob_blocked (op, newmap, x, y)) |
273 | if (ob_blocked (op, newmap, x, y)) |
279 | { /* First choice blocked */ |
274 | { /* First choice blocked */ |
280 | /* We try to find a spot for the player, starting closest in. |
275 | /* We try to find a spot for the player, starting closest in. |
281 | * We could use find_first_free_spot, but that doesn't randomize it at all, |
276 | * We could use find_first_free_spot, but that doesn't randomize it at all, |
… | |
… | |
290 | { |
285 | { |
291 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); |
286 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); |
292 | if (i == -1) |
287 | if (i == -1) |
293 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); |
288 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); |
294 | } |
289 | } |
|
|
290 | |
295 | if (i != -1) |
291 | if (i != -1) |
296 | { |
292 | { |
297 | x += freearr_x[i]; |
293 | x += freearr_x[i]; |
298 | y += freearr_y[i]; |
294 | y += freearr_y[i]; |
299 | } |
295 | } |
… | |
… | |
302 | /* not much we can do in this case. */ |
298 | /* not much we can do in this case. */ |
303 | LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", newmap->path, x, y); |
299 | LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", newmap->path, x, y); |
304 | } |
300 | } |
305 | } /* end if looking for free spot */ |
301 | } /* end if looking for free spot */ |
306 | |
302 | |
307 | if (op->map != NULL) |
303 | if (op->map) |
308 | { |
|
|
309 | INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (op->map), ARG_MAP (newmap)); |
|
|
310 | INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)); |
304 | if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) |
311 | } |
305 | return; |
|
|
306 | |
|
|
307 | if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) |
|
|
308 | return; |
|
|
309 | |
|
|
310 | if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (op->contr), ARG_INT (x), ARG_INT (y))) |
|
|
311 | return; |
312 | |
312 | |
313 | /* If it is a player login, he has yet to be inserted anyplace. |
313 | /* If it is a player login, he has yet to be inserted anyplace. |
314 | * otherwise, we need to deal with removing the player here. |
314 | * otherwise, we need to deal with removing the player here. |
315 | */ |
315 | */ |
316 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
|
|
317 | remove_ob (op); |
316 | remove_ob (op); |
318 | |
317 | |
319 | /* remove_ob clears these so they must be reset after the remove_ob call */ |
318 | /* remove_ob clears these so they must be reset after the remove_ob call */ |
320 | op->x = x; |
319 | op->x = x; |
321 | op->y = y; |
320 | op->y = y; |
322 | op->map = newmap; |
321 | op->map = newmap; |
|
|
322 | |
323 | insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); |
323 | insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); |
324 | |
|
|
325 | INVOKE_MAP (ENTER, op->map, ARG_PLAYER (op->contr)); |
|
|
326 | |
324 | |
327 | if (!op->contr->hidden) |
325 | if (!op->contr->hidden) |
328 | newmap->players++; |
326 | newmap->players++; |
329 | |
327 | |
330 | newmap->timeout = 0; |
328 | newmap->timeout = 0; |
… | |
… | |
341 | { |
339 | { |
342 | int i = find_free_spot (op->contr->ranges[range_golem], newmap, |
340 | int i = find_free_spot (op->contr->ranges[range_golem], newmap, |
343 | x, y, 1, SIZEOFFREE); |
341 | x, y, 1, SIZEOFFREE); |
344 | |
342 | |
345 | remove_ob (op->contr->ranges[range_golem]); |
343 | remove_ob (op->contr->ranges[range_golem]); |
|
|
344 | |
346 | if (i == -1) |
345 | if (i == -1) |
347 | { |
346 | { |
348 | remove_friendly_object (op->contr->ranges[range_golem]); |
347 | remove_friendly_object (op->contr->ranges[range_golem]); |
349 | free_object (op->contr->ranges[range_golem]); |
348 | free_object (op->contr->ranges[range_golem]); |
350 | op->contr->ranges[range_golem] = NULL; |
349 | op->contr->ranges[range_golem] = 0; |
351 | op->contr->golem_count = 0; |
|
|
352 | } |
350 | } |
353 | else |
351 | else |
354 | { |
352 | { |
355 | object *tmp; |
|
|
356 | |
|
|
357 | for (tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) |
353 | for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) |
358 | { |
354 | { |
359 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
355 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
360 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
356 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
361 | tmp->map = newmap; |
357 | tmp->map = newmap; |
362 | } |
358 | } |
|
|
359 | |
363 | insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); |
360 | insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); |
364 | op->contr->ranges[range_golem]->direction = |
361 | op->contr->ranges[range_golem]->direction = |
365 | find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y); |
362 | find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y); |
366 | } |
363 | } |
367 | } |
364 | } |
|
|
365 | |
368 | op->direction = 0; |
366 | op->direction = 0; |
369 | |
367 | |
370 | /* since the players map is already loaded, we don't need to worry |
368 | /* since the players map is already loaded, we don't need to worry |
371 | * about pending objects. |
369 | * about pending objects. |
372 | */ |
370 | */ |
… | |
… | |
387 | } |
385 | } |
388 | } |
386 | } |
389 | } |
387 | } |
390 | |
388 | |
391 | void |
389 | void |
392 | set_map_timeout (mapstruct *oldmap) |
390 | set_map_timeout (maptile *oldmap) |
393 | { |
391 | { |
394 | #if MAP_MAXTIMEOUT |
392 | #if MAP_MAXTIMEOUT |
395 | oldmap->timeout = MAP_TIMEOUT (oldmap); |
393 | oldmap->timeout = MAP_TIMEOUT (oldmap); |
396 | /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is |
394 | /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is |
397 | * lower than the min value. |
395 | * lower than the min value. |
398 | */ |
396 | */ |
399 | # if MAP_MINTIMEOUT |
397 | # if MAP_MINTIMEOUT |
400 | if (oldmap->timeout < MAP_MINTIMEOUT) |
398 | if (oldmap->timeout < MAP_MINTIMEOUT) |
401 | { |
|
|
402 | oldmap->timeout = MAP_MINTIMEOUT; |
399 | oldmap->timeout = MAP_MINTIMEOUT; |
403 | } |
|
|
404 | # endif |
400 | # endif |
|
|
401 | |
405 | if (oldmap->timeout > MAP_MAXTIMEOUT) |
402 | if (oldmap->timeout > MAP_MAXTIMEOUT) |
406 | { |
|
|
407 | oldmap->timeout = MAP_MAXTIMEOUT; |
403 | oldmap->timeout = MAP_MAXTIMEOUT; |
408 | } |
404 | |
409 | #else |
405 | #else |
410 | /* save out the map */ |
406 | /* save out the map */ |
411 | swap_map (oldmap); |
407 | swap_map (oldmap); |
412 | #endif /* MAP_MAXTIMEOUT */ |
408 | #endif /* MAP_MAXTIMEOUT */ |
413 | } |
409 | } |
… | |
… | |
418 | */ |
414 | */ |
419 | char * |
415 | char * |
420 | clean_path (const char *file) |
416 | clean_path (const char *file) |
421 | { |
417 | { |
422 | static char newpath[MAX_BUF], *cp; |
418 | static char newpath[MAX_BUF], *cp; |
|
|
419 | assign (newpath, file); |
423 | |
420 | |
424 | strncpy (newpath, file, MAX_BUF - 1); |
|
|
425 | newpath[MAX_BUF - 1] = '\0'; |
|
|
426 | for (cp = newpath; *cp != '\0'; cp++) |
421 | for (cp = newpath; *cp != '\0'; cp++) |
427 | { |
|
|
428 | if (*cp == '/') |
422 | if (*cp == '/') |
429 | *cp = '_'; |
423 | *cp = '_'; |
430 | } |
424 | |
431 | return newpath; |
425 | return newpath; |
432 | } |
426 | } |
433 | |
427 | |
434 | |
428 | |
435 | /* unclean_path takes a path and replaces all _ with / |
429 | /* unclean_path takes a path and replaces all _ with / |
… | |
… | |
443 | unclean_path (const char *src) |
437 | unclean_path (const char *src) |
444 | { |
438 | { |
445 | static char newpath[MAX_BUF], *cp; |
439 | static char newpath[MAX_BUF], *cp; |
446 | |
440 | |
447 | cp = strrchr (src, '/'); |
441 | cp = strrchr (src, '/'); |
448 | if (cp) |
442 | assign (newpath, cp ? cp + 1 : src); |
449 | strncpy (newpath, cp + 1, MAX_BUF - 1); |
|
|
450 | else |
|
|
451 | strncpy (newpath, src, MAX_BUF - 1); |
|
|
452 | newpath[MAX_BUF - 1] = '\0'; |
|
|
453 | |
443 | |
454 | for (cp = newpath; *cp != '\0'; cp++) |
444 | for (cp = newpath; *cp != '\0'; cp++) |
455 | { |
|
|
456 | if (*cp == '_') |
445 | if (*cp == '_') |
457 | *cp = '/'; |
446 | *cp = '/'; |
458 | } |
447 | |
459 | return newpath; |
448 | return newpath; |
460 | } |
449 | } |
461 | |
450 | |
462 | |
451 | |
463 | /* The player is trying to enter a randomly generated map. In this case, generate the |
452 | /* The player is trying to enter a randomly generated map. In this case, generate the |
… | |
… | |
465 | */ |
454 | */ |
466 | |
455 | |
467 | static void |
456 | static void |
468 | enter_random_map (object *pl, object *exit_ob) |
457 | enter_random_map (object *pl, object *exit_ob) |
469 | { |
458 | { |
470 | mapstruct *new_map; |
459 | maptile *new_map; |
471 | char newmap_name[HUGE_BUF], *cp; |
460 | char newmap_name[HUGE_BUF], *cp; |
472 | static int reference_number = 0; |
461 | static int reference_number = 0; |
473 | RMParms rp; |
462 | RMParms rp; |
474 | |
463 | |
475 | memset (&rp, 0, sizeof (RMParms)); |
464 | memset (&rp, 0, sizeof (RMParms)); |
… | |
… | |
535 | */ |
524 | */ |
536 | |
525 | |
537 | static void |
526 | static void |
538 | enter_fixed_template_map (object *pl, object *exit_ob) |
527 | enter_fixed_template_map (object *pl, object *exit_ob) |
539 | { |
528 | { |
540 | mapstruct *new_map; |
529 | maptile *new_map; |
541 | char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; |
530 | char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; |
542 | const char *new_map_name; |
531 | const char *new_map_name; |
543 | |
532 | |
544 | /* Split the exit path string into two parts, one |
533 | /* Split the exit path string into two parts, one |
545 | * for where to store the map, and one for were |
534 | * for where to store the map, and one for were |
… | |
… | |
554 | */ |
543 | */ |
555 | LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", |
544 | LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", |
556 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
545 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
557 | return; |
546 | return; |
558 | } |
547 | } |
|
|
548 | |
559 | *sourcemap++ = '\0'; |
549 | *sourcemap++ = '\0'; |
560 | |
550 | |
561 | /* If we are not coming from a template map, we can use relative directories |
551 | /* If we are not coming from a template map, we can use relative directories |
562 | * for the map to generate from. |
552 | * for the map to generate from. |
563 | */ |
553 | */ |
564 | if (!exit_ob->map->templatemap) |
554 | if (!exit_ob->map->templatemap) |
565 | { |
|
|
566 | sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); |
555 | sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); |
567 | } |
|
|
568 | |
556 | |
569 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
557 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
570 | * of the exit, and the name of the map the exit is on, respectively. |
558 | * of the exit, and the name of the map the exit is on, respectively. |
571 | */ |
559 | */ |
572 | sprintf (tmpnum, "%d", exit_ob->x); |
560 | sprintf (tmpnum, "%d", exit_ob->x); |
… | |
… | |
581 | |
569 | |
582 | /* If we are coming from another template map, use reletive paths unless |
570 | /* If we are coming from another template map, use reletive paths unless |
583 | * indicated otherwise. |
571 | * indicated otherwise. |
584 | */ |
572 | */ |
585 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
573 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
586 | { |
|
|
587 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
574 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
588 | } |
|
|
589 | else |
575 | else |
590 | { |
|
|
591 | new_map_name = create_template_pathname (resultname); |
576 | new_map_name = create_template_pathname (resultname); |
592 | } |
|
|
593 | |
577 | |
594 | /* Attempt to load the map, if unable to, then |
578 | /* Attempt to load the map, if unable to, then |
595 | * create the map from the template. |
579 | * create the map from the template. |
596 | */ |
580 | */ |
597 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
581 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
… | |
… | |
619 | LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n", |
603 | LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n", |
620 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
604 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
621 | } |
605 | } |
622 | } |
606 | } |
623 | |
607 | |
624 | |
|
|
625 | /* The player is trying to enter a randomly generated template map. In this |
608 | /* The player is trying to enter a randomly generated template map. In this |
626 | * case, generate the map as needed. |
609 | * case, generate the map as needed. |
627 | */ |
610 | */ |
628 | |
611 | |
629 | static void |
612 | static void |
630 | enter_random_template_map (object *pl, object *exit_ob) |
613 | enter_random_template_map (object *pl, object *exit_ob) |
631 | { |
614 | { |
632 | mapstruct *new_map; |
615 | maptile *new_map; |
633 | char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; |
616 | char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; |
634 | const char *new_map_name; |
617 | const char *new_map_name; |
635 | RMParms rp; |
618 | RMParms rp; |
636 | |
619 | |
637 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
620 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
… | |
… | |
699 | */ |
682 | */ |
700 | static void |
683 | static void |
701 | enter_unique_map (object *op, object *exit_ob) |
684 | enter_unique_map (object *op, object *exit_ob) |
702 | { |
685 | { |
703 | char apartment[HUGE_BUF]; |
686 | char apartment[HUGE_BUF]; |
704 | mapstruct *newmap; |
687 | maptile *newmap; |
705 | |
688 | |
706 | if (EXIT_PATH (exit_ob)[0] == '/') |
689 | if (EXIT_PATH (exit_ob)[0] == '/') |
707 | { |
690 | { |
708 | sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); |
691 | sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); |
709 | newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE); |
692 | newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE); |
… | |
… | |
793 | #define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
776 | #define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
794 | object *tmp; |
777 | object *tmp; |
795 | |
778 | |
796 | /* It may be nice to support other creatures moving across |
779 | /* It may be nice to support other creatures moving across |
797 | * exits, but right now a lot of the code looks at op->contr, |
780 | * exits, but right now a lot of the code looks at op->contr, |
798 | * so thta is an RFE. |
781 | * so that is an RFE. |
799 | */ |
782 | */ |
800 | if (op->type != PLAYER) |
783 | if (op->type != PLAYER) |
801 | return; |
784 | return; |
802 | |
785 | |
803 | /* First, lets figure out what map the player is going to go to */ |
786 | /* First, lets figure out what map the player is going to go to */ |
804 | if (exit_ob) |
787 | if (exit_ob) |
805 | { |
788 | { |
806 | |
|
|
807 | /* check to see if we make a template map */ |
789 | /* check to see if we make a template map */ |
808 | if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') |
790 | if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') |
809 | { |
791 | { |
810 | if (EXIT_PATH (exit_ob)[2] == '!') |
792 | if (EXIT_PATH (exit_ob)[2] == '!') |
811 | { |
793 | { |
… | |
… | |
832 | int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); |
814 | int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); |
833 | |
815 | |
834 | /* 'Normal' exits that do not do anything special |
816 | /* 'Normal' exits that do not do anything special |
835 | * Simple enough we don't need another routine for it. |
817 | * Simple enough we don't need another routine for it. |
836 | */ |
818 | */ |
837 | mapstruct *newmap; |
819 | maptile *newmap; |
838 | |
820 | |
839 | if (exit_ob->map) |
821 | if (exit_ob->map) |
840 | { |
822 | { |
841 | newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); |
823 | newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); |
842 | /* Random map was previously generated, but is no longer about. Lets generate a new |
824 | /* Random map was previously generated, but is no longer about. Lets generate a new |
… | |
… | |
931 | hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); |
913 | hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); |
932 | } |
914 | } |
933 | else |
915 | else |
934 | { |
916 | { |
935 | int flags = 0; |
917 | int flags = 0; |
936 | mapstruct *newmap; |
918 | maptile *newmap; |
937 | |
|
|
938 | |
919 | |
939 | /* Hypothetically, I guess its possible that a standard map matches |
920 | /* Hypothetically, I guess its possible that a standard map matches |
940 | * the localdir, but that seems pretty unlikely - unlikely enough that |
921 | * the localdir, but that seems pretty unlikely - unlikely enough that |
941 | * I'm not going to attempt to try to deal with that possibility. |
922 | * I'm not going to attempt to try to deal with that possibility. |
942 | * We use the fact that when a player saves on a unique map, it prepends |
923 | * We use the fact that when a player saves on a unique map, it prepends |
… | |
… | |
963 | { |
944 | { |
964 | LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); |
945 | LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); |
965 | abort (); |
946 | abort (); |
966 | } |
947 | } |
967 | } |
948 | } |
|
|
949 | |
968 | enter_map (op, newmap, op->x, op->y); |
950 | enter_map (op, newmap, op->x, op->y); |
969 | } |
951 | } |
970 | } |
952 | } |
971 | |
953 | |
972 | /* |
954 | /* |
… | |
… | |
977 | |
959 | |
978 | #if 0 // dead code, schmorp |
960 | #if 0 // dead code, schmorp |
979 | void |
961 | void |
980 | process_active_maps () |
962 | process_active_maps () |
981 | { |
963 | { |
982 | for (mapstruct *map = first_map; map != NULL; map = map->next) |
964 | for (maptile *map = first_map; map != NULL; map = map->next) |
983 | if (map->in_memory == MAP_IN_MEMORY) |
965 | if (map->in_memory == MAP_IN_MEMORY) |
984 | if (players_on_map (map, TRUE)) |
966 | if (players_on_map (map, TRUE)) |
985 | process_events (map); |
967 | process_events (map); |
986 | } |
968 | } |
987 | #endif |
969 | #endif |
… | |
… | |
993 | * objects have been updated, process_players2() does the processing that |
975 | * objects have been updated, process_players2() does the processing that |
994 | * is needed after the players have been updated. |
976 | * is needed after the players have been updated. |
995 | */ |
977 | */ |
996 | |
978 | |
997 | void |
979 | void |
998 | process_players1 (mapstruct *map) |
980 | process_players1 (maptile *map) |
999 | { |
981 | { |
1000 | int flag; |
982 | int flag; |
1001 | player *pl, *plnext; |
983 | player *pl, *plnext; |
1002 | |
984 | |
1003 | /* Basically, we keep looping until all the players have done their actions. */ |
985 | /* Basically, we keep looping until all the players have done their actions. */ |
… | |
… | |
1070 | /* draw(pl->ob); *//* updated in socket code */ |
1052 | /* draw(pl->ob); *//* updated in socket code */ |
1071 | } |
1053 | } |
1072 | } |
1054 | } |
1073 | |
1055 | |
1074 | void |
1056 | void |
1075 | process_players2 (mapstruct *map) |
1057 | process_players2 (maptile *map) |
1076 | { |
1058 | { |
1077 | player *pl; |
1059 | player *pl; |
1078 | |
1060 | |
1079 | /* Then check if any players should use weapon-speed instead of speed */ |
1061 | /* Then check if any players should use weapon-speed instead of speed */ |
1080 | for (pl = first_player; pl != NULL; pl = pl->next) |
1062 | for (pl = first_player; pl != NULL; pl = pl->next) |
… | |
… | |
1110 | pl->ob->speed_left = pl->ob->speed; |
1092 | pl->ob->speed_left = pl->ob->speed; |
1111 | } |
1093 | } |
1112 | } |
1094 | } |
1113 | |
1095 | |
1114 | void |
1096 | void |
1115 | process_events (mapstruct *map) |
1097 | process_events (maptile *map) |
1116 | { |
1098 | { |
1117 | object *op; |
1099 | object *op; |
|
|
1100 | |
|
|
1101 | static object *marker; |
|
|
1102 | if (!marker) |
1118 | object *marker = get_object (); |
1103 | marker = get_object (); |
1119 | tag_t tag; |
|
|
1120 | |
1104 | |
1121 | process_players1 (map); |
1105 | process_players1 (map); |
1122 | |
1106 | |
1123 | marker->active_next = active_objects; |
1107 | marker->active_next = active_objects; |
1124 | |
1108 | |
… | |
… | |
1129 | active_objects = marker; |
1113 | active_objects = marker; |
1130 | |
1114 | |
1131 | while (marker->active_next) |
1115 | while (marker->active_next) |
1132 | { |
1116 | { |
1133 | op = marker->active_next; |
1117 | op = marker->active_next; |
1134 | tag = op->count; |
|
|
1135 | |
1118 | |
1136 | /* Move marker forward - swap op and marker */ |
1119 | /* Move marker forward - swap op and marker */ |
1137 | op->active_prev = marker->active_prev; |
1120 | op->active_prev = marker->active_prev; |
1138 | |
1121 | |
1139 | if (op->active_prev) |
1122 | if (op->active_prev) |
… | |
… | |
1169 | * around. |
1152 | * around. |
1170 | */ |
1153 | */ |
1171 | if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) |
1154 | if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) |
1172 | { |
1155 | { |
1173 | LOG (llevError, "BUG: process_events(): Removed object on list\n"); |
1156 | LOG (llevError, "BUG: process_events(): Removed object on list\n"); |
1174 | dump_object (op); |
1157 | char *dump = dump_object (op); |
1175 | LOG (llevError, errmsg); |
1158 | LOG (llevError, dump); |
|
|
1159 | free (dump); |
1176 | free_object (op); |
1160 | free_object (op); |
1177 | continue; |
1161 | continue; |
1178 | } |
1162 | } |
1179 | |
1163 | |
1180 | if (!op->speed) |
1164 | if (!op->speed) |
… | |
… | |
1226 | LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); |
1210 | LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); |
1227 | } |
1211 | } |
1228 | #endif |
1212 | #endif |
1229 | --op->speed_left; |
1213 | --op->speed_left; |
1230 | process_object (op); |
1214 | process_object (op); |
|
|
1215 | |
1231 | if (was_destroyed (op, tag)) |
1216 | if (op->destroyed ()) |
1232 | continue; |
1217 | continue; |
1233 | } |
1218 | } |
|
|
1219 | |
1234 | if (settings.casting_time == TRUE && op->casting_time > 0) |
1220 | if (settings.casting_time == TRUE && op->casting_time > 0) |
1235 | op->casting_time--; |
1221 | op->casting_time--; |
|
|
1222 | |
1236 | if (op->speed_left <= 0) |
1223 | if (op->speed_left <= 0) |
1237 | op->speed_left += FABS (op->speed); |
1224 | op->speed_left += FABS (op->speed); |
1238 | } |
1225 | } |
1239 | |
1226 | |
1240 | /* Remove marker object from active list */ |
1227 | /* Remove marker object from active list */ |
… | |
… | |
1242 | marker->active_prev->active_next = NULL; |
1229 | marker->active_prev->active_next = NULL; |
1243 | else |
1230 | else |
1244 | active_objects = NULL; |
1231 | active_objects = NULL; |
1245 | |
1232 | |
1246 | process_players2 (map); |
1233 | process_players2 (map); |
1247 | |
|
|
1248 | free_object (marker); |
|
|
1249 | } |
1234 | } |
1250 | |
1235 | |
1251 | void |
1236 | void |
1252 | clean_tmp_files (void) |
1237 | clean_tmp_files (void) |
1253 | { |
1238 | { |
1254 | mapstruct *m, *next; |
1239 | maptile *m, *next; |
1255 | |
1240 | |
1256 | LOG (llevInfo, "Cleaning up...\n"); |
1241 | LOG (llevInfo, "Cleaning up...\n"); |
1257 | |
1242 | |
1258 | /* We save the maps - it may not be intuitive why, but if there are unique |
1243 | /* We save the maps - it may not be intuitive why, but if there are unique |
1259 | * items, we need to save the map so they get saved off. Perhaps we should |
1244 | * items, we need to save the map so they get saved off. Perhaps we should |
… | |
… | |
1286 | |
1271 | |
1287 | /* clean up everything before exiting */ |
1272 | /* clean up everything before exiting */ |
1288 | void |
1273 | void |
1289 | cleanup (void) |
1274 | cleanup (void) |
1290 | { |
1275 | { |
1291 | LOG (llevDebug, "Cleanup called. freeing data.\n"); |
1276 | LOG (llevDebug, "Cleanup called.\n"); |
|
|
1277 | |
|
|
1278 | for (player *pl = first_player; pl != NULL; pl = pl->next) |
|
|
1279 | save_player (pl->ob, 0); |
|
|
1280 | |
|
|
1281 | for (player *pl = first_player; pl != NULL; pl = pl->next) |
|
|
1282 | if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1283 | leave_map (pl->ob); |
|
|
1284 | |
1292 | clean_tmp_files (); |
1285 | clean_tmp_files (); |
1293 | write_book_archive (); |
1286 | write_book_archive (); |
1294 | #ifdef MEMORY_DEBUG |
|
|
1295 | free_all_maps (); |
|
|
1296 | free_style_maps (); |
|
|
1297 | free_all_object_data (); |
|
|
1298 | free_all_archs (); |
|
|
1299 | free_all_treasures (); |
|
|
1300 | free_all_images (); |
|
|
1301 | free_all_newserver (); |
|
|
1302 | free_all_recipes (); |
|
|
1303 | free_all_readable (); |
|
|
1304 | free_all_god (); |
|
|
1305 | free_all_anim (); |
|
|
1306 | /* See what the string data that is out there that hasn't been freed. */ |
|
|
1307 | |
1287 | |
1308 | /* LOG(llevDebug, ss_dump_table(0xff));*/ |
1288 | INVOKE_GLOBAL (CLEANUP); |
1309 | #endif |
1289 | |
1310 | exit (0); |
1290 | _exit (0); |
1311 | } |
1291 | } |
1312 | |
1292 | |
1313 | void |
1293 | void |
1314 | leave (player *pl, int draw_exit) |
1294 | leave (player *pl, int draw_exit) |
1315 | { |
1295 | { |
… | |
… | |
1434 | flush_old_maps (); /* Clears the tmp-files of maps which have reset */ |
1414 | flush_old_maps (); /* Clears the tmp-files of maps which have reset */ |
1435 | |
1415 | |
1436 | if (!(pticks % 2503)) |
1416 | if (!(pticks % 2503)) |
1437 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
1417 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
1438 | |
1418 | |
1439 | if (!(pticks % 2521)) |
|
|
1440 | metaserver_update (); /* 2500 ticks is about 5 minutes */ |
|
|
1441 | |
|
|
1442 | if (!(pticks % 5003)) |
1419 | if (!(pticks % 5003)) |
1443 | write_book_archive (); |
1420 | write_book_archive (); |
1444 | |
1421 | |
1445 | if (!(pticks % 5009)) |
1422 | if (!(pticks % 5009)) |
1446 | clean_friendly_list (); |
1423 | clean_friendly_list (); |
… | |
… | |
1472 | main (int argc, char **argv) |
1449 | main (int argc, char **argv) |
1473 | { |
1450 | { |
1474 | settings.argc = argc; |
1451 | settings.argc = argc; |
1475 | settings.argv = argv; |
1452 | settings.argv = argv; |
1476 | |
1453 | |
1477 | cfperl_init (); |
|
|
1478 | |
|
|
1479 | init (argc, argv); |
1454 | init (argc, argv); |
1480 | |
1455 | |
1481 | initPlugins (); |
1456 | initPlugins (); |
1482 | |
1457 | |
1483 | for (;;) |
1458 | for (;;) |