Crossfire Server, Trunk  1.75.0
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 
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  play_again(pl);
90  pl->speed = 0;
92 }
player::bed_y
int16_t bed_y
x,y - coordinates of respawn (savebed).
Definition: player.h:111
living::exp
int64_t exp
Experience.
Definition: living.h:47
PLAYER
@ PLAYER
Definition: object.h:112
global.h
EVENT_LOGOUT
#define EVENT_LOGOUT
Player logout.
Definition: events.h:58
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
pets_terminate_all
void pets_terminate_all(object *owner)
Removes all pets someone owns.
Definition: pets.cpp:242
MSG_TYPE_ADMIN_PLAYER
#define MSG_TYPE_ADMIN_PLAYER
Player coming/going/death.
Definition: newclient.h:500
player::bed_x
int16_t bed_x
Definition: player.h:111
register_apply
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.cpp:62
object::speed
float speed
Frequency of object 'moves' relative to server tick rate.
Definition: object.h:337
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
object::x
int16_t x
Definition: object.h:335
object::map
struct mapstruct * map
Pointer to the map in which this object is present.
Definition: object.h:305
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
object::direction
int8_t direction
Means the object is moving that way.
Definition: object.h:344
player::savebed_map
char savebed_map[MAX_BUF]
Map where player will respawn after death.
Definition: player.h:110
NDI_RED
#define NDI_RED
Definition: newclient.h:249
mapstruct::path
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:355
hiscore_check
void hiscore_check(object *op, int quiet)
Checks if player should enter the hiscore, and if so writes her into the list.
Definition: hiscore.cpp:348
object::y
int16_t y
Position in the map for this object.
Definition: object.h:335
object::contr
struct player * contr
Pointer to the player which control this object.
Definition: object.h:284
player::killer
char killer[BIG_NAME]
Who killed this player.
Definition: player.h:190
play_again
void play_again(object *op)
Ask the player whether to play again or disconnect.
Definition: player.cpp:908
SAVEBED
@ SAVEBED
Definition: object.h:224
party_leave
void party_leave(object *op)
Makes a player leave his party.
Definition: party.cpp:123
socket_struct::host
char * host
Which host it is connected from (ip address).
Definition: newserver.h:104
object_update_speed
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.cpp:1334
object::type
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:348
sproto.h
MSG_TYPE_ADMIN_LOADSAVE
#define MSG_TYPE_ADMIN_LOADSAVE
load/save operations
Definition: newclient.h:503
method_ret
char method_ret
Define some standard return values for callbacks which don't need to return any other results.
Definition: ob_methods.h:14
ob_types.h
sounds.h
NDI_UNIQUE
#define NDI_UNIQUE
Print immediately, don't buffer.
Definition: newclient.h:266
object::name
sstring name
The name of the object, obviously...
Definition: object.h:319
init_type_savebed
void init_type_savebed(void)
Initializer for the SAVEBED object type.
Definition: savebed.cpp:34
NDI_ALL
#define NDI_ALL
Inform all players of this message.
Definition: newclient.h:267
NDI_DK_ORANGE
#define NDI_DK_ORANGE
DarkOrange2.
Definition: newclient.h:252
save_player
int save_player(object *op, int flag)
Saves a player to disk.
Definition: login.cpp:239
object_remove
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to.
Definition: object.cpp:1818
player::socket
socket_struct * socket
Socket information for this player.
Definition: player.h:107
ob_methods.h
object::stats
living stats
Str, Con, Dex, etc.
Definition: object.h:378
apply_savebed
static void apply_savebed(object *pl)
Apply a bed to reality.
Definition: savebed.cpp:60
MSG_TYPE_ADMIN
#define MSG_TYPE_ADMIN
Definition: newclient.h:406
events_execute_global_event
void events_execute_global_event(int eventcode,...)
Execute a global event.
Definition: events.cpp:30
savebed_type_apply
static method_ret savebed_type_apply(object *op, object *applier, int aflags)
Attempts to apply a savebed.
Definition: savebed.cpp:46