Crossfire Server, Trunk
savebed.cpp
Go to the documentation of this file.
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 <crossfire@metalforge.org>.
12  */
13 
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(object *op, object *applier, int aflags);
29 static void apply_savebed(object *pl);
30 
34 void init_type_savebed(void) {
36 }
37 
46 static method_ret savebed_type_apply(object *op, object *applier, int aflags) {
47  (void)op;
48  (void)aflags;
49  if (applier->type == PLAYER)
50  apply_savebed(applier);
51  return METHOD_OK;
52 }
53 
60 static void apply_savebed(object *pl) {
61  /* Refuse to save a player without any experience. */
62  if (!pl->stats.exp) {
65  "You must gain a bit of experience before you can save.");
66  return;
67  }
68 
69  events_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 */
74  pl->direction = 0;
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  play_again(pl);
90  pl->speed = 0;
92 }
PLAYER
@ PLAYER
Definition: object.h:112
global.h
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
pets_terminate_all
void pets_terminate_all(object *owner)
Definition: pets.cpp:225
MSG_TYPE_ADMIN_PLAYER
#define MSG_TYPE_ADMIN_PLAYER
Definition: newclient.h:499
register_apply
void register_apply(int ob_type, apply_func method)
Definition: ob_types.cpp:62
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
NDI_RED
#define NDI_RED
Definition: newclient.h:248
EVENT_LOGOUT
#define EVENT_LOGOUT
Definition: events.h:45
hiscore_check
void hiscore_check(object *op, int quiet)
Definition: hiscore.cpp:348
play_again
void play_again(object *op)
Definition: player.cpp:903
SAVEBED
@ SAVEBED
Definition: object.h:224
party_leave
void party_leave(object *op)
Definition: party.cpp:123
object_update_speed
void object_update_speed(object *op)
Definition: object.cpp:1349
object::type
uint8_t type
Definition: object.h:348
sproto.h
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
MSG_TYPE_ADMIN_LOADSAVE
#define MSG_TYPE_ADMIN_LOADSAVE
Definition: newclient.h:502
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:265
init_type_savebed
void init_type_savebed(void)
Definition: savebed.cpp:34
give.op
op
Definition: give.py:33
NDI_ALL
#define NDI_ALL
Definition: newclient.h:266
NDI_DK_ORANGE
#define NDI_DK_ORANGE
Definition: newclient.h:251
save_player
int save_player(object *op, int flag)
Definition: login.cpp:230
object_remove
void object_remove(object *op)
Definition: object.cpp:1833
ob_methods.h
apply_savebed
static void apply_savebed(object *pl)
Definition: savebed.cpp:60
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
MSG_TYPE_ADMIN
#define MSG_TYPE_ADMIN
Definition: newclient.h:405
events_execute_global_event
void events_execute_global_event(int eventcode,...)
Definition: events.cpp:32
savebed_type_apply
static method_ret savebed_type_apply(object *op, object *applier, int aflags)
Definition: savebed.cpp:46