Debian Codegraph @

types/player_changer/player_changer.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file
16 * The implementation of the PLAYER_CHANGER class of objects.
17 */
18 #include "global.h"
19
20 #include <string.h>
21
22 #include "ob_methods.h"
23 #include "ob_types.h"
24 #include "sounds.h"
25 #include "sproto.h"
26
27 static method_ret player_changer_type_process(ob_methods *context, object *op);
28
29 /**
30 * Initializer for the player changer object type.
31 */
32 void init_type_player_changer(void) {
33 register_process(PLAYER_CHANGER, player_changer_type_process);
34 }
35
36 /**
37 * Move for ::PLAYER_CHANGER.
38 *
39 * This object will teleport someone to a different map
40 * and will also apply changes to the player from its inventory.
41 *
42 * This was invented for giving classes, but there's no reason it
43 * can't be generalized.
44 *
45 * @param context The method context
46 * @param op The player changer that's being processed.
47 * @return METHOD_OK
48 */
49 static method_ret player_changer_type_process(ob_methods *context, object *op) {
50 object *player;
51 char c;
52
53 if (!op->above || !EXIT_PATH(op))
54 return METHOD_OK;
55
56 /* This isn't all that great - means that the player_mover
57 * needs to be on top.
58 */
59 if (op->above->type == PLAYER) {
60 /* Lauwenmark: Handle for plugin TRIGGER event */
61 if (execute_event(op, EVENT_TRIGGER, op->above, NULL, NULL, SCRIPT_FIX_NOTHING) != 0)
62 return METHOD_OK;
63 player = op->above;
64 FOR_INV_PREPARE(op, walk)
65 apply_changes_to_player(player, walk, AC_PLAYER_STAT_LIMIT);
66 FOR_INV_FINISH();
67
68 fix_object(player);
69 esrv_send_inventory(op->above, op->above);
70 esrv_update_item(UPD_FACE, op->above, op->above);
71
72 /* update players death & WoR home-position */
73 sscanf(EXIT_PATH(op), "%c", &c);
74 if (c == '/') {
75 safe_strncpy(player->contr->savebed_map, EXIT_PATH(op),
76 sizeof(player->contr->savebed_map));
77 player->contr->bed_x = EXIT_X(op);
78 player->contr->bed_y = EXIT_Y(op);
79 } else
80 LOG(llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", EXIT_PATH(op));
81
82 enter_exit(op->above, op);
83 save_player(player, 1);
84 }
85
86 return METHOD_OK;
87 }