Crossfire Server, Trunk
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;
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  for (uint8_t db = 0; db < pl->delayed_buffers_allocated; db++) {
51  free(pl->delayed_buffers[db]);
52  }
56  if (pl->last_exit != NULL) {
58  pl->last_exit = NULL;
59  }
60 }
61 
69  if (first_player != pl) {
70  player *prev = first_player;
71 
72  while (prev != NULL && prev->next != NULL && prev->next != pl)
73  prev = prev->next;
74  if (!prev || prev->next != pl) {
75  LOG(llevError, "Free_player: Can't find previous player.\n");
76  exit(1);
77  }
78  prev->next = pl->next;
79  } else
80  first_player = pl->next;
81 
82  if (pl->ob != NULL) {
83  if (!QUERY_FLAG(pl->ob, FLAG_REMOVED))
86  }
87 
89 
90  free(pl->socket.faces_sent);
91 
92  free(pl);
93 }
94 
106 int atnr_is_dragon_enabled(int attacknr) {
107  if (attacknr == ATNR_MAGIC
108  || attacknr == ATNR_FIRE
109  || attacknr == ATNR_ELECTRICITY
110  || attacknr == ATNR_COLD
111  || attacknr == ATNR_ACID
112  || attacknr == ATNR_POISON)
113  return 1;
114  return 0;
115 }
116 
125 int is_dragon_pl(const object *op) {
126  if (op != NULL
127  && op->type == PLAYER
128  && op->arch != NULL
129  && op->arch->clone.race != NULL
130  && strcmp(op->arch->clone.race, "dragon") == 0)
131  return 1;
132  return 0;
133 }
134 
148  client_spell *info = pl->spell_state;
149 
150  while (info) {
151  if (info->spell == spell)
152  return info;
153  info = info->next;
154  }
155  /*
156  * Why take the time to malloc() and then memset()?
157  * Just calloc and its good to go!
158  */
159  info = (client_spell *)calloc(1, sizeof(client_spell));
160  if (info == NULL)
162  info->next = pl->spell_state;
163  info->spell = spell;
164  pl->spell_state = info;
165  return info;
166 }
167 
176 int is_wraith_pl(object *op) {
177  return op != NULL && op->type == PLAYER && op->arch != NULL && object_find_by_name(op, "wraith feed") != NULL;
178 }
179 
188 int is_old_wraith_pl(object *op) {
189  return op != NULL && op->type == PLAYER && op->arch != NULL && object_find_by_name(op, "Wraith_Force") != NULL && !is_wraith_pl(op);
190 }
191 
205 void player_set_dragon_title(struct pl *pl, int level, const char *attack, int skin_resist) {
206  if (level == 0)
207  snprintf(pl->title, sizeof(pl->title), "%s hatchling", attack);
208  else if (level == 1)
209  snprintf(pl->title, sizeof(pl->title), "%s wyrm", attack);
210  else if (level == 2)
211  snprintf(pl->title, sizeof(pl->title), "%s wyvern", attack);
212  else if (level == 3)
213  snprintf(pl->title, sizeof(pl->title), "%s dragon", attack);
214  /* special titles for extra high resistance! */
215  else if (skin_resist > 80)
216  snprintf(pl->title, sizeof(pl->title), "legendary %s dragon", attack);
217  else if (skin_resist > 50)
218  snprintf(pl->title, sizeof(pl->title), "ancient %s dragon", attack);
219  else
220  snprintf(pl->title, sizeof(pl->title), "big %s dragon", attack);
221  pl->own_title[0] = '\0';
222 }
223 
235 void player_get_title(const struct pl *pl, char *buf, size_t bufsize) {
236  if (pl->own_title[0] == '\0')
237  snprintf(buf, bufsize, "the %s", pl->title);
238  else
239  strlcpy(buf, pl->own_title, bufsize);
240 }
241 
250 int player_has_own_title(const struct pl *pl) {
251  return pl->own_title[0] != '\0';
252 }
253 
263 const char *player_get_own_title(const struct pl *pl) {
264  return pl->own_title;
265 }
266 
275 void player_set_own_title(struct pl *pl, const char *title) {
276  strlcpy(pl->own_title, title, sizeof(pl->own_title));
278 }
279 
290 void link_player_skills(object *op) {
291  int skill;
293  if (tmp->type == SKILL) {
294  for (skill = 0; skill < MAX_SKILLS; skill++) {
295  if (op->contr->last_skill_ob[skill] == NULL) {
296  /* Didn't find the skill, so add it */
297  op->contr->last_skill_ob[skill] = tmp;
298  op->contr->last_skill_exp[skill] = -1;
299  break;
300  }
301  if (op->contr->last_skill_ob[skill] == tmp) {
302  /* Skill already linked, nothing to do */
303  break;
304  }
305  }
306  }
307  } FOR_INV_FINISH();
308 }
give.next
def next
Definition: give.py:44
pl::delayed_buffers
SockList ** delayed_buffers
Definition: player.h:211
PLAYER
@ PLAYER
Definition: object.h:107
global.h
FREE_OBJ_NO_DESTROY_CALLBACK
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:532
object_free
void object_free(object *ob, int flags)
Definition: object.c:1565
object_remove
void object_remove(object *op)
Definition: object.c:1806
llevError
@ llevError
Definition: logger.h:11
client_spell
Definition: player.h:74
ATNR_ACID
#define ATNR_ACID
Definition: attack.h:55
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
client_spell::next
struct client_spell * next
Definition: player.h:79
player_has_own_title
int player_has_own_title(const struct pl *pl)
Definition: player.c:250
pl::socket
socket_struct socket
Definition: player.h:94
pl
Definition: player.h:92
pl::ob
object * ob
Definition: player.h:162
SKILL
@ SKILL
Definition: object.h:143
pl::delayed_buffers_used
uint8_t delayed_buffers_used
Definition: player.h:210
Ice.tmp
int tmp
Definition: Ice.py:207
player_set_own_title
void player_set_own_title(struct pl *pl, const char *title)
Definition: player.c:275
is_old_wraith_pl
int is_old_wraith_pl(object *op)
Definition: player.c:188
pl::next
struct pl * next
Definition: player.h:93
link_player_skills
void link_player_skills(object *op)
Definition: player.c:290
titlestruct
Definition: readable.c:107
pl::unarmed_skill
const char * unarmed_skill
Definition: player.h:206
fatal
void fatal(enum fatal_error err)
Definition: utils.c:597
client_spell::spell
object * spell
Definition: player.h:75
first_player
EXTERN player * first_player
Definition: global.h:115
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:675
clear_player
void clear_player(player *pl)
Definition: player.c:33
ATNR_POISON
#define ATNR_POISON
Definition: attack.h:59
replace_unprintable_chars
void replace_unprintable_chars(char *buf)
Definition: utils.c:474
MAX_SKILLS
#define MAX_SKILLS
Definition: skills.h:70
player_get_own_title
const char * player_get_own_title(const struct pl *pl)
Definition: player.c:263
get_client_spell_state
client_spell * get_client_spell_state(player *pl, object *spell)
Definition: player.c:147
is_dragon_pl
int is_dragon_pl(const object *op)
Definition: player.c:125
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.c:220
FREE_AND_CLEAR_STR
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:196
ATNR_FIRE
#define ATNR_FIRE
Definition: attack.h:51
pl::spell_state
client_spell * spell_state
Definition: player.h:200
is_wraith_pl
int is_wraith_pl(object *op)
Definition: player.c:176
FLAG_REMOVED
#define FLAG_REMOVED
Definition: define.h:232
FREE_AND_CLEAR
#define FREE_AND_CLEAR(xyz)
Definition: global.h:191
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
pl::delayed_buffers_allocated
uint8_t delayed_buffers_allocated
Definition: player.h:209
give.op
op
Definition: give.py:33
ATNR_MAGIC
#define ATNR_MAGIC
Definition: attack.h:50
pl::stack_position
int stack_position
Definition: player.h:204
buf
StringBuffer * buf
Definition: readable.c:1606
pl::own_title
char own_title[MAX_NAME]
Definition: player.h:167
socket_struct::faces_sent
uint8_t * faces_sent
Definition: newserver.h:96
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1533
pl::last_exit
struct obj * last_exit
Definition: player.h:193
free_player
void free_player(player *pl)
Definition: player.c:68
object_find_by_name
object * object_find_by_name(const object *who, const char *name)
Definition: object.c:3964
ATNR_COLD
#define ATNR_COLD
Definition: attack.h:53
atnr_is_dragon_enabled
int atnr_is_dragon_enabled(int attacknr)
Definition: player.c:106
pl::stack_items
tag_t * stack_items
Definition: player.h:202
player_set_dragon_title
void player_set_dragon_title(struct pl *pl, int level, const char *attack, int skin_resist)
Definition: player.c:205
ATNR_ELECTRICITY
#define ATNR_ELECTRICITY
Definition: attack.h:52
player_get_title
void player_get_title(const struct pl *pl, char *buf, size_t bufsize)
Definition: player.c:235
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:668
pl::title
char title[BIG_NAME]
Definition: player.h:169
level
Definition: level.py:1