Crossfire Server, Trunk  R20608
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  /* Lauwenmark : Here we handle the LOGOUT global event */
70 
71  /* Need to call pets_terminate_all() before we remove the player ob */
73  object_remove(pl);
74  pl->direction = 0;
77  "%s leaves the game.", pl->name);
78 
79  /* update respawn position */
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 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:315
char path[HUGE_BUF]
Definition: map.h:365
Definition: player.h:92
#define NDI_ALL
Definition: newclient.h:246
int16_t bed_x
Definition: player.h:98
int save_player(object *op, int flag)
Definition: login.c:211
socket_struct socket
Definition: player.h:94
#define EVENT_LOGOUT
Definition: plugin.h:89
void play_again(object *op)
Definition: player.c:878
int64_t exp
Definition: living.h:46
#define MSG_TYPE_ADMIN_LOADSAVE
Definition: newclient.h:477
void party_leave(object *op)
Definition: party.c:104
#define safe_strncpy
Definition: compat.h:23
void pets_terminate_all(object *owner)
Definition: pets.c:231
static method_ret savebed_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Definition: savebed.c:47
char savebed_map[MAX_BUF]
Definition: player.h:97
#define NDI_DK_ORANGE
Definition: newclient.h:227
char * host
Definition: newserver.h:110
char method_ret
Definition: ob_methods.h:14
int16_t y
Definition: object.h:326
#define NDI_RED
Definition: newclient.h:224
#define METHOD_OK
Definition: ob_methods.h:15
#define MSG_TYPE_ADMIN_PLAYER
Definition: newclient.h:474
struct mapdef * map
Definition: object.h:297
#define MAP_TIMEOUT(m)
Definition: map.h:66
const char * name
Definition: object.h:311
int16_t bed_y
Definition: player.h:98
int execute_global_event(int eventcode,...)
Definition: main.c:369
int8_t direction
Definition: object.h:334
void hiscore_check(object *op, int quiet)
Definition: hiscore.c:302
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:62
struct pl * contr
Definition: object.h:276
float speed
Definition: object.h:328
void init_type_savebed(void)
Definition: savebed.c:34
#define MSG_TYPE_ADMIN
Definition: newclient.h:377
int16_t x
Definition: object.h:326
Definition: object.h:107
char killer[BIG_NAME]
Definition: player.h:171
living stats
Definition: object.h:368
uint8_t type
Definition: object.h:338
#define MAP_SWAP_TIME(m)
Definition: map.h:67
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:1129
void object_remove(object *op)
Definition: object.c:1654