Crossfire Server, Trunk
player.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 <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)
48  FREE_AND_CLEAR_STR(pl->unarmed_skill);
49 
50  for (uint8_t db = 0; db < pl->delayed_buffers_allocated; db++) {
51  free(pl->delayed_buffers[db]);
52  }
53  FREE_AND_CLEAR(pl->delayed_buffers);
54  pl->delayed_buffers_allocated = 0;
55  pl->delayed_buffers_used = 0;
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))
84  object_remove(pl->ob);
86  }
87 
89  free(pl);
90 }
91 
103 int atnr_is_dragon_enabled(int attacknr) {
104  if (attacknr == ATNR_MAGIC
105  || attacknr == ATNR_FIRE
106  || attacknr == ATNR_ELECTRICITY
107  || attacknr == ATNR_COLD
108  || attacknr == ATNR_ACID
109  || attacknr == ATNR_POISON)
110  return 1;
111  return 0;
112 }
113 
122 int is_dragon_pl(const object *op) {
123  if (op != NULL
124  && op->type == PLAYER
125  && op->arch != NULL
126  && op->arch->clone.race != NULL
127  && strcmp(op->arch->clone.race, "dragon") == 0)
128  return 1;
129  return 0;
130 }
131 
145  client_spell *info = pl->spell_state;
146 
147  while (info) {
148  if (info->spell == spell)
149  return info;
150  info = info->next;
151  }
152  /*
153  * Why take the time to malloc() and then memset()?
154  * Just calloc and its good to go!
155  */
156  info = (client_spell *)calloc(1, sizeof(client_spell));
157  if (info == NULL)
159  info->next = pl->spell_state;
160  info->spell = spell;
161  pl->spell_state = info;
162  return info;
163 }
164 
173 int is_wraith_pl(object *op) {
174  return op != NULL && op->type == PLAYER && op->arch != NULL && object_find_by_name(op, "wraith feed") != NULL;
175 }
176 
185 int is_old_wraith_pl(object *op) {
186  return op != NULL && op->type == PLAYER && op->arch != NULL && object_find_by_name(op, "Wraith_Force") != NULL && !is_wraith_pl(op);
187 }
188 
202 void player_set_dragon_title(player *pl, int level, const char *attack, int skin_resist) {
203  if (level == 0)
204  snprintf(pl->title, sizeof(pl->title), "%s hatchling", attack);
205  else if (level == 1)
206  snprintf(pl->title, sizeof(pl->title), "%s wyrm", attack);
207  else if (level == 2)
208  snprintf(pl->title, sizeof(pl->title), "%s wyvern", attack);
209  else if (level == 3)
210  snprintf(pl->title, sizeof(pl->title), "%s dragon", attack);
211  /* special titles for extra high resistance! */
212  else if (skin_resist > 80)
213  snprintf(pl->title, sizeof(pl->title), "legendary %s dragon", attack);
214  else if (skin_resist > 50)
215  snprintf(pl->title, sizeof(pl->title), "ancient %s dragon", attack);
216  else
217  snprintf(pl->title, sizeof(pl->title), "big %s dragon", attack);
218  pl->own_title[0] = '\0';
219 }
220 
232 void player_get_title(const player *pl, char *buf, size_t bufsize) {
233  if (pl->own_title[0] == '\0')
234  snprintf(buf, bufsize, "the %s", pl->title);
235  else
236  strlcpy(buf, pl->own_title, bufsize);
237 }
238 
247 int player_has_own_title(const struct player *pl) {
248  return pl->own_title[0] != '\0';
249 }
250 
260 const char *player_get_own_title(const struct player *pl) {
261  return pl->own_title;
262 }
263 
272 void player_set_own_title(struct player *pl, const char *title) {
273  strlcpy(pl->own_title, title, sizeof(pl->own_title));
274  replace_unprintable_chars(pl->own_title);
275 }
276 
287 void link_player_skills(object *op) {
288  int skill;
290  if (tmp->type == SKILL) {
291  for (skill = 0; skill < MAX_SKILLS; skill++) {
292  if (op->contr->last_skill_ob[skill] == NULL) {
293  /* Didn't find the skill, so add it */
294  op->contr->last_skill_ob[skill] = tmp;
295  op->contr->last_skill_exp[skill] = -1;
296  break;
297  }
298  if (op->contr->last_skill_ob[skill] == tmp) {
299  /* Skill already linked, nothing to do */
300  break;
301  }
302  }
303  }
304  } FOR_INV_FINISH();
305 }
306 
307 void commit_crime(object *op, const char *description) {
308  object *force = add_force(op, "criminal", 25); // 5 minutes
309  object_set_msg(force, description);
310 }
311 
312 bool is_criminal(object *op) {
313  return find_force(op, "criminal");
314 }
give.next
def next
Definition: give.py:44
PLAYER
@ PLAYER
Definition: object.h:112
player::next
player * next
Definition: player.h:106
global.h
FREE_OBJ_NO_DESTROY_CALLBACK
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:545
first_player
player * first_player
Definition: init.cpp:106
llevError
@ llevError
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:58
client_spell
Definition: player.h:87
player
Definition: player.h:105
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:92
player_set_own_title
void player_set_own_title(struct player *pl, const char *title)
Definition: player.cpp:272
SKILL
@ SKILL
Definition: object.h:148
player_has_own_title
int player_has_own_title(const struct player *pl)
Definition: player.cpp:247
Ice.tmp
int tmp
Definition: Ice.py:207
buf
StringBuffer * buf
Definition: readable.cpp:1565
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.cpp:1560
object_find_by_name
object * object_find_by_name(const object *who, const char *name)
Definition: object.cpp:3956
is_criminal
bool is_criminal(object *op)
Definition: player.cpp:312
commit_crime
void commit_crime(object *op, const char *description)
Definition: player.cpp:307
client_spell::spell
object * spell
Definition: player.h:88
object_free
void object_free(object *ob, int flags)
Definition: object.cpp:1592
title
Definition: readable.cpp:108
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
ATNR_POISON
#define ATNR_POISON
Definition: attack.h:59
MAX_SKILLS
#define MAX_SKILLS
Definition: skills.h:70
replace_unprintable_chars
void replace_unprintable_chars(char *buf)
Definition: utils.cpp:447
fatal
void fatal(enum fatal_error err)
Definition: utils.cpp:590
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.cpp:222
is_wraith_pl
int is_wraith_pl(object *op)
Definition: player.cpp:173
FREE_AND_CLEAR_STR
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:198
ATNR_FIRE
#define ATNR_FIRE
Definition: attack.h:51
FLAG_REMOVED
#define FLAG_REMOVED
Definition: define.h:232
get_client_spell_state
client_spell * get_client_spell_state(player *pl, object *spell)
Definition: player.cpp:144
FREE_AND_CLEAR
#define FREE_AND_CLEAR(xyz)
Definition: global.h:193
is_dragon_pl
int is_dragon_pl(const object *op)
Definition: player.cpp:122
give.op
op
Definition: give.py:33
object_set_msg
void object_set_msg(object *op, const char *msg)
Definition: object.cpp:4811
ATNR_MAGIC
#define ATNR_MAGIC
Definition: attack.h:50
add_force
object * add_force(object *op, const char *name, int duration)
Definition: object.cpp:5430
atnr_is_dragon_enabled
int atnr_is_dragon_enabled(int attacknr)
Definition: player.cpp:103
find_force
object * find_force(object *op, const char *name)
Definition: object.cpp:5425
player_set_dragon_title
void player_set_dragon_title(player *pl, int level, const char *attack, int skin_resist)
Definition: player.cpp:202
object_remove
void object_remove(object *op)
Definition: object.cpp:1833
ATNR_COLD
#define ATNR_COLD
Definition: attack.h:53
is_old_wraith_pl
int is_old_wraith_pl(object *op)
Definition: player.cpp:185
player_get_own_title
const char * player_get_own_title(const struct player *pl)
Definition: player.cpp:260
ATNR_ELECTRICITY
#define ATNR_ELECTRICITY
Definition: attack.h:52
clear_player
void clear_player(player *pl)
Definition: player.cpp:33
link_player_skills
void link_player_skills(object *op)
Definition: player.cpp:287
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
free_player
void free_player(player *pl)
Definition: player.cpp:68
player_get_title
void player_get_title(const player *pl, char *buf, size_t bufsize)
Definition: player.cpp:232
dragon_attune.force
force
Definition: dragon_attune.py:45
level
Definition: level.py:1