Debian Codegraph @

types/savebed/savebed.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 * Implement beds that are applied to save a player to disk.
17 */
18
19 #include "global.h"
20
21 #include <string.h>
22
23 #include "ob_methods.h"
24 #include "ob_types.h"
25 #include "sounds.h"
26 #include "sproto.h"
27
28 static method_ret savebed_type_apply(ob_methods *context, object *op, object *applier, int aflags);
29 static void apply_savebed(object *pl);
30
31 /**
32 * Initializer for the SAVEBED object type.
33 */
34 void init_type_savebed(void) {
35 register_apply(SAVEBED, savebed_type_apply);
36 }
37
38 /**
39 * Attempts to apply a savebed.
40 * @param context The method context
41 * @param op The savebed to apply
42 * @param applier The object attempting to apply the savebed. Ignore if not
43 * a player
44 * @param aflags Special flags (always apply/unapply)
45 * @return The return value is always METHOD_OK
46 */
47 static method_ret savebed_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
48 if (applier->type == PLAYER)
49 apply_savebed(applier);
50 return METHOD_OK;
51 }
52
53 /**
54 * Apply a bed to reality.
55 *
56 * @param pl
57 * player who is applying the bed.
58 */
59 static void apply_savebed(object *pl) {
60 /* Refuse to save a player without any experience. */
61 if (!pl->stats.exp) {
62 draw_ext_info_format(NDI_UNIQUE | NDI_RED, 5, pl,
63 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOADSAVE,
64 "You must gain a bit of experience before you can save.");
65 return;
66 }
67
68 /* Lauwenmark : Here we handle the LOGOUT global event */
69 execute_global_event(EVENT_LOGOUT, pl->contr, pl->contr->socket.host);
70
71 /* Need to call pets_terminate_all() before we remove the player ob */
72 pets_terminate_all(pl);
73 object_remove(pl);
74 pl->direction = 0;
75 draw_ext_info_format(NDI_UNIQUE|NDI_ALL|NDI_DK_ORANGE, 5, pl,
76 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER,
77 "%s leaves the game.", pl->name);
78
79 /* update respawn position */
80 safe_strncpy(pl->contr->savebed_map, pl->map->path,
81 sizeof(pl->contr->savebed_map));
82 pl->contr->bed_x = pl->x;
83 pl->contr->bed_y = pl->y;
84
85 strcpy(pl->contr->killer, "left");
86 hiscore_check(pl, 0); /* Always check score */
87 save_player(pl, 0);
88 party_leave(pl);
89 #if MAP_MAXTIMEOUT
90 MAP_SWAP_TIME(pl->map) = MAP_TIMEOUT(pl->map);
91 #endif
92 play_again(pl);
93 pl->speed = 0;
94 object_update_speed(pl);
95 }