Crossfire Server, Trunk  R20513
player.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 <stdlib.h>
22 #include <string.h>
23 
34  client_spell *info;
35  client_spell *next;
36 
37  /* Clear item stack (used by DMs only) */
38  free(pl->stack_items);
39  pl->stack_position = 0;
40 
41  info = pl->spell_state;
42  while (info) {
43  next = info->next;
44  free(info);
45  info = next;
46  }
47  if (pl->unarmed_skill)
49 }
50 
58  if (first_player != pl) {
59  player *prev = first_player;
60 
61  while (prev != NULL && prev->next != NULL && prev->next != pl)
62  prev = prev->next;
63  if (prev->next != pl) {
64  LOG(llevError, "Free_player: Can't find previous player.\n");
65  exit(1);
66  }
67  prev->next = pl->next;
68  } else
69  first_player = pl->next;
70 
71  if (pl->ob != NULL) {
72  if (!QUERY_FLAG(pl->ob, FLAG_REMOVED))
73  object_remove(pl->ob);
75  }
76 
77  clear_player(pl);
78 
79  free(pl->socket.faces_sent);
80 
81  free(pl);
82 }
83 
95 int atnr_is_dragon_enabled(int attacknr) {
96  if (attacknr == ATNR_MAGIC
97  || attacknr == ATNR_FIRE
98  || attacknr == ATNR_ELECTRICITY
99  || attacknr == ATNR_COLD
100  || attacknr == ATNR_ACID
101  || attacknr == ATNR_POISON)
102  return 1;
103  return 0;
104 }
105 
114 int is_dragon_pl(const object *op) {
115  if (op != NULL
116  && op->type == PLAYER
117  && op->arch != NULL
118  && op->arch->clone.race != NULL
119  && strcmp(op->arch->clone.race, "dragon") == 0)
120  return 1;
121  return 0;
122 }
123 
137  client_spell *info = pl->spell_state;
138 
139  while (info) {
140  if (info->spell == spell)
141  return info;
142  info = info->next;
143  }
144  /*
145  * Why take the time to malloc() and then memset()?
146  * Just calloc and its good to go!
147  */
148  info = (client_spell *)calloc(1, sizeof(client_spell));
149  if (info == NULL)
151  info->next = pl->spell_state;
152  info->spell = spell;
153  pl->spell_state = info;
154  return info;
155 }
156 
165 int is_wraith_pl(object *op) {
166  return op != NULL && op->type == PLAYER && op->arch != NULL && object_find_by_name(op, "wraith feed") != NULL;
167 }
168 
177 int is_old_wraith_pl(object *op) {
178  return op != NULL && op->type == PLAYER && op->arch != NULL && object_find_by_name(op, "Wraith_Force") != NULL && !is_wraith_pl(op);
179 }
180 
194 void player_set_dragon_title(struct pl *pl, int level, const char *attack, int skin_resist) {
195  if (level == 0)
196  snprintf(pl->title, sizeof(pl->title), "%s hatchling", attack);
197  else if (level == 1)
198  snprintf(pl->title, sizeof(pl->title), "%s wyrm", attack);
199  else if (level == 2)
200  snprintf(pl->title, sizeof(pl->title), "%s wyvern", attack);
201  else if (level == 3)
202  snprintf(pl->title, sizeof(pl->title), "%s dragon", attack);
203  /* special titles for extra high resistance! */
204  else if (skin_resist > 80)
205  snprintf(pl->title, sizeof(pl->title), "legendary %s dragon", attack);
206  else if (skin_resist > 50)
207  snprintf(pl->title, sizeof(pl->title), "ancient %s dragon", attack);
208  else
209  snprintf(pl->title, sizeof(pl->title), "big %s dragon", attack);
210  pl->own_title[0] = '\0';
211 }
212 
224 void player_get_title(const struct pl *pl, char *buf, size_t bufsize) {
225  if (pl->own_title[0] == '\0')
226  snprintf(buf, bufsize, "the %s", pl->title);
227  else
228  snprintf(buf, bufsize, "%s", pl->own_title);
229 }
230 
239 int player_has_own_title(const struct pl *pl) {
240  return pl->own_title[0] != '\0';
241 }
242 
252 const char *player_get_own_title(const struct pl *pl) {
253  return pl->own_title;
254 }
255 
264 void player_set_own_title(struct pl *pl, const char *title) {
265  snprintf(pl->own_title, sizeof(pl->own_title), "%s", title);
267 }
Error, serious thing.
Definition: logger.h:11
One player.
Definition: player.h:92
void free_player(player *pl)
Clears player structure, including pointed object (through object_free_drop_inventory()).
Definition: player.c:57
const char * race
Human, goblin, dragon, etc.
Definition: object.h:318
char title[BIG_NAME]
Default title, like fighter, wizard, etc.
Definition: player.h:165
void player_get_title(const struct pl *pl, char *buf, size_t bufsize)
Returns the player&#39;s title.
Definition: player.c:224
Information on one title.
Definition: readable.c:106
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
Definition: utils.c:596
object * spell
Spell object this structure is about.
Definition: player.h:75
object clone
An object from which to do object_copy()
Definition: object.h:470
socket_struct socket
Socket information for this player.
Definition: player.h:94
This stores, for a spell a player knows, the last sp/gr/dam information sent to client.
Definition: player.h:74
Global type definitions and header inclusions.
object * object_find_by_name(const object *who, const char *name)
Finds an object in inventory name.
Definition: object.c:3879
#define FLAG_REMOVED
Object is not in any map or invenory.
Definition: define.h:232
int stack_position
Current stack position, 0 for no item.
Definition: player.h:200
const char * player_get_own_title(const struct pl *pl)
Returns the player&#39;s own title.
Definition: player.c:252
client_spell * get_client_spell_state(player *pl, object *spell)
Gets the (client-side) spell state for specified spell.
Definition: player.c:136
int player_has_own_title(const struct pl *pl)
Returns whether the player has a custom title.
Definition: player.c:239
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1368
void clear_player(player *pl)
Clears data in player structure.
Definition: player.c:33
void player_set_own_title(struct pl *pl, const char *title)
Sets the custom title.
Definition: player.c:264
int is_wraith_pl(object *op)
Tests if a player is a wraith.
Definition: player.c:165
int is_dragon_pl(const object *op)
Checks if player is a dragon.
Definition: player.c:114
#define snprintf
Definition: win32.h:46
tag_t * stack_items
Item stack for patch/dump/...
Definition: player.h:198
#define ATNR_MAGIC
Definition: attack.h:50
#define FREE_AND_CLEAR_STR(xyz)
Release the shared string, and set it to NULL.
Definition: global.h:208
#define ATNR_ELECTRICITY
Definition: attack.h:52
#define ATNR_POISON
Definition: attack.h:59
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
int is_old_wraith_pl(object *op)
Checks if player is a wraith without the &#39;wraith feed&#39; skill.
Definition: player.c:177
char own_title[MAX_NAME]
Title the player has chosen for themself.
Definition: player.h:163
void replace_unprintable_chars(char *buf)
Replaces any unprintable character in the given buffer with a space.
Definition: utils.c:473
client_spell * spell_state
Spell information sent to client.
Definition: player.h:196
object * ob
The object representing the player.
Definition: player.h:158
See Player.
Definition: object.h:107
struct client_spell * next
Next spell information.
Definition: player.h:79
void player_set_dragon_title(struct pl *pl, int level, const char *attack, int skin_resist)
Updates the title of a dragon player to reflect the current level, attack type, and resistances...
Definition: player.c:194
struct archt * arch
Pointer to archetype.
Definition: object.h:412
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
EXTERN player * first_player
First player.
Definition: global.h:117
struct pl * next
Pointer to next player, NULL if this is last.
Definition: player.h:93
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
#define ATNR_COLD
Definition: attack.h:53
const char * unarmed_skill
Prefered skill to use in unarmed combat.
Definition: player.h:202
#define ATNR_ACID
Definition: attack.h:55
uint8_t * faces_sent
This is a bitmap on sent face status.
Definition: newserver.h:106
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.c:1654
int atnr_is_dragon_enabled(int attacknr)
Determine if the attacktype represented by the specified attack-number is enabled for dragon players...
Definition: player.c:95
#define ATNR_FIRE
Definition: attack.h:51