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
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:536
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:51
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
Ice.tmp
int tmp
Definition: Ice.py:207
player_has_own_title
int player_has_own_title(const struct player *pl)
Definition: player.cpp:247
buf
StringBuffer * buf
Definition: readable.cpp:1552
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.cpp:1555
object_find_by_name
object * object_find_by_name(const object *who, const char *name)
Definition: object.cpp:3947
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
description
spell prayer lvl t sp speed range duration short description
Definition: spell-summary.txt:2
spell
with a maximum of six This is not so if you are wearing plate you receive no benefit Armour is additive with all the supplementry forms of which means that it lasts until the next semi permanent spell effect is cast upon the character spell
Definition: tome-of-magic.txt:44
object_free
void object_free(object *ob, int flags)
Definition: object.cpp:1587
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
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
fatal
void fatal(enum fatal_error err)
Definition: utils.cpp:570
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:4802
ATNR_MAGIC
#define ATNR_MAGIC
Definition: attack.h:50
exit
Install Bug reporting Credits but rather whatever guild name you are using *With the current map and server there are three they and GreenGoblin *Whatever name you give the folder should but it will still use GUILD_TEMPLATE *You can change what guild it uses by editing the map files Modify Map or objects if you want to use the optional Python based Guild Storage hall The first three are on the main the next two are in the guild_hq and the final one is in hallofjoining Withe the Storage three objects are found on the main floor and the last two are in the basement It s not that but you will need a map editor You find the object that has the click edit and change the line script options(which currently is "GUILD_TEMPALTE") to the guild you wish to use. And make sure you use the same one for all of them or it won 't work. Here 's a quick HOWTO for using the map editor to make these changes edit the mainfloor map exit(x15, y29 - set to/Edit/This/Exit/Path in the template) back to the world map as well. If you are using the Storage Hall map(storage_hall)
add_force
object * add_force(object *op, const char *name, int duration)
Definition: object.cpp:5414
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:5409
player_set_dragon_title
void player_set_dragon_title(player *pl, int level, const char *attack, int skin_resist)
Definition: player.cpp:202
skill
skill
Definition: arch-handbook.txt:585
object_remove
void object_remove(object *op)
Definition: object.cpp:1828
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
replace_unprintable_chars
void replace_unprintable_chars(char *buf)
Definition: utils.cpp:447
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