Crossfire Server, Trunk
savebed.c
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 
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 #if MAP_MAXTIMEOUT
90  MAP_SWAP_TIME(pl->map) = MAP_TIMEOUT(pl->map);
91 #endif
92  play_again(pl);
93  pl->speed = 0;
95 }
PLAYER
@ PLAYER
Definition: object.h:107
global.h
object_remove
void object_remove(object *op)
Definition: object.c:1819
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
pets_terminate_all
void pets_terminate_all(object *owner)
Definition: pets.c:225
MSG_TYPE_ADMIN_PLAYER
#define MSG_TYPE_ADMIN_PLAYER
Definition: newclient.h:496
pl::socket
socket_struct socket
Definition: player.h:107
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
pl
Definition: player.h:105
NDI_RED
#define NDI_RED
Definition: newclient.h:245
EVENT_LOGOUT
#define EVENT_LOGOUT
Definition: events.h:44
hiscore_check
void hiscore_check(object *op, int quiet)
Definition: hiscore.c:346
pl::savebed_map
char savebed_map[MAX_BUF]
Definition: player.h:110
play_again
void play_again(object *op)
Definition: player.c:895
SAVEBED
@ SAVEBED
Definition: object.h:219
party_leave
void party_leave(object *op)
Definition: party.c:123
init_type_savebed
void init_type_savebed(void)
Definition: savebed.c:34
socket_struct::host
char * host
Definition: newserver.h:100
savebed_type_apply
static method_ret savebed_type_apply(object *op, object *applier, int aflags)
Definition: savebed.c:46
sproto.h
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
pl::bed_x
int16_t bed_x
Definition: player.h:111
MSG_TYPE_ADMIN_LOADSAVE
#define MSG_TYPE_ADMIN_LOADSAVE
Definition: newclient.h:499
register_apply
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:62
method_ret
char method_ret
Definition: ob_methods.h:14
pl::bed_y
int16_t bed_y
Definition: player.h:111
ob_types.h
sounds.h
obj::type
uint8_t type
Definition: object.h:343
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
give.op
op
Definition: give.py:33
NDI_ALL
#define NDI_ALL
Definition: newclient.h:263
pl::killer
char killer[BIG_NAME]
Definition: player.h:189
NDI_DK_ORANGE
#define NDI_DK_ORANGE
Definition: newclient.h:248
object_update_speed
void object_update_speed(object *op)
Definition: object.c:1330
save_player
int save_player(object *op, int flag)
Definition: login.c:230
ob_methods.h
MAP_TIMEOUT
#define MAP_TIMEOUT(m)
Definition: map.h:66
MSG_TYPE_ADMIN
#define MSG_TYPE_ADMIN
Definition: newclient.h:402
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,...)
Definition: main.c:319
events_execute_global_event
void events_execute_global_event(int eventcode,...)
Definition: events.cpp:29
apply_savebed
static void apply_savebed(object *pl)
Definition: savebed.c:60
MAP_SWAP_TIME
#define MAP_SWAP_TIME(m)
Definition: map.h:67