Crossfire Server  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 }
Sound-related defines.
#define NDI_ALL
Inform all players of this message.
Definition: newclient.h:271
int8_t direction
Means the object is moving that way.
Definition: object.h:344
#define EVENT_LOGOUT
Player logout.
Definition: events.h:58
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
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
int save_player(object *op, int flag)
Saves a player to disk.
Definition: login.cpp:239
void play_again(object *op)
Ask the player whether to play again or disconnect.
Definition: player.cpp:908
int16_t y
Position in the map for this object.
Definition: object.h:335
#define MSG_TYPE_ADMIN_LOADSAVE
load/save operations
Definition: newclient.h:518
void party_leave(object *op)
Makes a player leave his party.
Definition: party.cpp:123
int16_t x
Definition: object.h:335
Global type definitions and header inclusions.
#define safe_strncpy
Definition: compat.h:27
struct player * contr
Pointer to the player which control this object.
Definition: object.h:284
void pets_terminate_all(object *owner)
Removes all pets someone owns.
Definition: pets.cpp:242
#define NDI_DK_ORANGE
DarkOrange2.
Definition: newclient.h:252
char * host
Which host it is connected from (ip address).
Definition: newserver.h:104
void events_execute_global_event(int eventcode,...)
Execute a global event.
Definition: events.cpp:30
int16_t bed_x
Definition: player.h:113
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
#define NDI_RED
Definition: newclient.h:249
float speed
Frequency of object &#39;moves&#39; relative to server tick rate.
Definition: object.h:337
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:360
#define METHOD_OK
Definition: ob_methods.h:15
#define MSG_TYPE_ADMIN_PLAYER
Player coming/going/death.
Definition: newclient.h:515
socket_struct * socket
Socket information for this player.
Definition: player.h:109
static void apply_savebed(object *pl)
Apply a bed to reality.
Definition: savebed.cpp:60
static method_ret savebed_type_apply(object *op, object *applier, int aflags)
Attempts to apply a savebed.
Definition: savebed.cpp:46
char killer[BIG_NAME]
Who killed this player.
Definition: player.h:192
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
int16_t bed_y
x,y - coordinates of respawn (savebed).
Definition: player.h:113
char savebed_map[MAX_BUF]
Map where player will respawn after death.
Definition: player.h:112
living stats
Str, Con, Dex, etc.
Definition: object.h:378
#define MSG_TYPE_ADMIN
Definition: newclient.h:418
struct mapstruct * map
Pointer to the map in which this object is present.
Definition: object.h:305
Object type variables.
See Player.
Definition: object.h:112
void init_type_savebed(void)
Initializer for the SAVEBED object type.
Definition: savebed.cpp:34
sstring name
The name of the object, obviously...
Definition: object.h:319
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:348
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.cpp:1334
int64_t exp
Experience.
Definition: living.h:47
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:270
Object type functions and variables.
See Savebed.
Definition: object.h:224
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.cpp:62