… | |
… | |
2426 | int |
2426 | int |
2427 | is_legal_2ways_exit (object *op, object *exit) |
2427 | is_legal_2ways_exit (object *op, object *exit) |
2428 | { |
2428 | { |
2429 | object *tmp; |
2429 | object *tmp; |
2430 | object *exit_owner; |
2430 | object *exit_owner; |
2431 | player *pp; |
|
|
2432 | maptile *exitmap; |
2431 | maptile *exitmap; |
2433 | |
2432 | |
2434 | if (exit->stats.exp != 1) |
2433 | if (exit->stats.exp != 1) |
2435 | return 1; /*This is not a 2 way, so it is legal */ |
2434 | return 1; /*This is not a 2 way, so it is legal */ |
|
|
2435 | |
2436 | if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) |
2436 | if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) |
2437 | return 0; /* This is a reset town portal */ |
2437 | return 0; /* This is a reset town portal */ |
|
|
2438 | |
2438 | /* To know if an exit has a correspondant, we look at |
2439 | /* To know if an exit has a correspondant, we look at |
2439 | * all the exits in destination and try to find one with same path as |
2440 | * all the exits in destination and try to find one with same path as |
2440 | * the current exit's position */ |
2441 | * the current exit's position */ |
2441 | if (!strncmp (EXIT_PATH (exit), settings.localdir, strlen (settings.localdir))) |
2442 | if (!strncmp (EXIT_PATH (exit), settings.localdir, strlen (settings.localdir))) |
2442 | exitmap = ready_map_name (EXIT_PATH (exit), MAP_PLAYER_UNIQUE); |
2443 | exitmap = ready_map_name (EXIT_PATH (exit), MAP_PLAYER_UNIQUE); |
2443 | else |
2444 | else |
2444 | exitmap = ready_map_name (EXIT_PATH (exit), 0); |
2445 | exitmap = ready_map_name (EXIT_PATH (exit), 0); |
|
|
2446 | |
2445 | if (exitmap) |
2447 | if (exitmap) |
2446 | { |
2448 | { |
2447 | tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit)); |
2449 | tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit)); |
|
|
2450 | |
2448 | if (!tmp) |
2451 | if (!tmp) |
2449 | return 0; |
2452 | return 0; |
|
|
2453 | |
2450 | for ((tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit))); tmp; tmp = tmp->above) |
2454 | for ((tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit))); tmp; tmp = tmp->above) |
2451 | { |
2455 | { |
2452 | if (tmp->type != EXIT) |
2456 | if (tmp->type != EXIT) |
2453 | continue; /*Not an exit */ |
2457 | continue; /*Not an exit */ |
|
|
2458 | |
2454 | if (!EXIT_PATH (tmp)) |
2459 | if (!EXIT_PATH (tmp)) |
2455 | continue; /*Not a valid exit */ |
2460 | continue; /*Not a valid exit */ |
|
|
2461 | |
2456 | if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y)) |
2462 | if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y)) |
2457 | continue; /*Not in the same place */ |
2463 | continue; /*Not in the same place */ |
|
|
2464 | |
2458 | if (strcmp (exit->map->path, EXIT_PATH (tmp)) != 0) |
2465 | if (strcmp (exit->map->path, EXIT_PATH (tmp)) != 0) |
2459 | continue; /*Not in the same map */ |
2466 | continue; /*Not in the same map */ |
2460 | |
2467 | |
2461 | /* From here we have found the exit is valid. However we do |
2468 | /* From here we have found the exit is valid. However we do |
2462 | * here the check of the exit owner. It is important for the |
2469 | * here the check of the exit owner. It is important for the |
2463 | * town portals to prevent strangers from visiting your appartments |
2470 | * town portals to prevent strangers from visiting your appartments |
2464 | */ |
2471 | */ |
2465 | if (!exit->race) |
2472 | if (!exit->race) |
2466 | return 1; /*No owner, free for all! */ |
2473 | return 1; /*No owner, free for all! */ |
|
|
2474 | |
2467 | exit_owner = NULL; |
2475 | exit_owner = NULL; |
2468 | for (pp = first_player; pp; pp = pp->next) |
2476 | |
|
|
2477 | for_all_players (pp) |
2469 | { |
2478 | { |
2470 | if (!pp->ob) |
2479 | if (!pp->ob) |
2471 | continue; |
2480 | continue; |
|
|
2481 | |
2472 | if (pp->ob->name != exit->race) |
2482 | if (pp->ob->name != exit->race) |
2473 | continue; |
2483 | continue; |
|
|
2484 | |
2474 | exit_owner = pp->ob; /*We found a player which correspond to the player name */ |
2485 | exit_owner = pp->ob; /*We found a player which correspond to the player name */ |
2475 | break; |
2486 | break; |
2476 | } |
2487 | } |
|
|
2488 | |
2477 | if (!exit_owner) |
2489 | if (!exit_owner) |
2478 | return 0; /* No more owner */ |
2490 | return 0; /* No more owner */ |
|
|
2491 | |
2479 | if (exit_owner->contr == op->contr) |
2492 | if (exit_owner->contr == op->contr) |
2480 | return 1; /*It is your exit */ |
2493 | return 1; /*It is your exit */ |
|
|
2494 | |
2481 | if (exit_owner && /*There is a owner */ |
2495 | if (exit_owner && /*There is a owner */ |
2482 | (op->contr) && /*A player tries to pass */ |
2496 | (op->contr) && /*A player tries to pass */ |
2483 | ((exit_owner->contr->party == NULL) || /*No pass if controller has no party */ |
2497 | ((exit_owner->contr->party == NULL) || /*No pass if controller has no party */ |
2484 | (exit_owner->contr->party != op->contr->party))) /* Or not the same as op */ |
2498 | (exit_owner->contr->party != op->contr->party))) /* Or not the same as op */ |
2485 | return 0; |
2499 | return 0; |
|
|
2500 | |
2486 | return 1; |
2501 | return 1; |
2487 | } |
2502 | } |
2488 | } |
2503 | } |
|
|
2504 | |
2489 | return 0; |
2505 | return 0; |
2490 | } |
2506 | } |
2491 | |
2507 | |
2492 | |
2508 | |
2493 | /** |
2509 | /** |