Crossfire Server, Trunk  R22047
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(ob_methods *context, object *op, object *applier, int aflags);
29 static void apply_savebed(object *pl);
30 
34 void init_type_savebed(void) {
36 }
37 
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 
59 static void apply_savebed(object *pl) {
60  /* Refuse to save a player without any experience. */
61  if (!pl->stats.exp) {
64  "You must gain a bit of experience before you can save.");
65  return;
66  }
67 
68  events_execute_global_event(EVENT_LOGOUT, pl->contr, pl->contr->socket.host);
69 
70  /* Need to call pets_terminate_all() before we remove the player ob */
72  object_remove(pl);
73  pl->direction = 0;
76  "%s leaves the game.", pl->name);
77 
78  /* update respawn position */
79  safe_strncpy(pl->contr->savebed_map, pl->map->path,
80  sizeof(pl->contr->savebed_map));
81  pl->contr->bed_x = pl->x;
82  pl->contr->bed_y = pl->y;
83 
84  strcpy(pl->contr->killer, "left");
85  hiscore_check(pl, 0); /* Always check score */
86  save_player(pl, 0);
87  party_leave(pl);
88 #if MAP_MAXTIMEOUT
89  MAP_SWAP_TIME(pl->map) = MAP_TIMEOUT(pl->map);
90 #endif
91  play_again(pl);
92  pl->speed = 0;
94 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:313
Definition: player.h:92
#define NDI_ALL
Definition: newclient.h:246
int save_player(object *op, int flag)
Definition: login.c:212
void play_again(object *op)
Definition: player.c:885
#define MSG_TYPE_ADMIN_LOADSAVE
Definition: newclient.h:477
void party_leave(object *op)
Definition: party.c:123
#define safe_strncpy
Definition: compat.h:23
void pets_terminate_all(object *owner)
Definition: pets.c:225
static method_ret savebed_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Definition: savebed.c:47
#define NDI_DK_ORANGE
Definition: newclient.h:227
void events_execute_global_event(int eventcode,...)
Definition: events.cpp:27
char method_ret
Definition: ob_methods.h:14
#define NDI_RED
Definition: newclient.h:224
#define METHOD_OK
Definition: ob_methods.h:15
#define MSG_TYPE_ADMIN_PLAYER
Definition: newclient.h:474
#define MAP_TIMEOUT(m)
Definition: map.h:66
void hiscore_check(object *op, int quiet)
Definition: hiscore.c:344
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:62
void init_type_savebed(void)
Definition: savebed.c:34
#define MSG_TYPE_ADMIN
Definition: newclient.h:377
#define MAP_SWAP_TIME(m)
Definition: map.h:67
#define EVENT_LOGOUT
Definition: events.h:44
static void apply_savebed(object *pl)
Definition: savebed.c:59
#define NDI_UNIQUE
Definition: newclient.h:245
void object_update_speed(object *op)
Definition: object.c:1086
void object_remove(object *op)
Definition: object.c:1588