Crossfire Server, Trunk
party.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 
24 #include "sproto.h"
25 
26 static partylist *firstparty = NULL;
27 static partylist *lastparty = NULL;
40 partylist *party_form(object *op, const char *partyname) {
41  partylist *party;
42  char buf[MAX_BUF];
43 
44  strlcpy(buf, partyname, sizeof(buf));
46 
47  if (party_find(buf) != NULL)
48  return NULL;
49 
50  party_leave(op);
51  party = (partylist *)malloc(sizeof(partylist));
52  party->partyname = strdup_local(buf);
53 #ifdef PARTY_KILL_LOG
54  party->total_exp = 0;
55  party->kills = 0;
56 #endif
57  party->passwd[0] = '\0';
58  party->next = NULL;
59  party->partyleader = strdup_local(op->name);
61  "You have formed party: %s",
62  party->partyname);
63  op->contr->party = party;
64 
65  if (lastparty) {
66  lastparty->next = party;
68  } else {
69  firstparty = party;
71  }
72 
73  return party;
74 }
75 
85 void party_join(object *op, partylist *party) {
86  char buf[MAX_BUF];
87 
88  if (op->contr->party == party) {
90  "You are already a member of party: %s",
91  party->partyname);
92  return;
93  }
94 
95  party_leave(op);
96 
97  op->contr->party = party;
99  "You have joined party: %s\n",
100  party->partyname);
101  snprintf(buf, MAX_BUF, "%s joins party %s", op->name, party->partyname);
103 }
104 
108 static void remove_if_unused(partylist *party) {
109  for (player *pl = first_player; pl != NULL; pl = pl->next) {
110  if (pl->party == party)
111  return;
112  }
113  party_remove(party);
114 }
115 
123 void party_leave(object *op) {
124  char buf[MAX_BUF];
125 
126  partylist *party = op->contr->party;
127  if (party == NULL) {
128  return;
129  }
130 
132  "You leave party %s.",
133  party->partyname);
134  snprintf(buf, sizeof(buf), "%s leaves party %s.", op->name, party->partyname);
136  op->contr->party = NULL;
137  remove_if_unused(party);
138 }
139 
148 partylist *party_find(const char *partyname) {
149  partylist *party;
150 
151  for (party = firstparty; party; party = party->next) {
152  if (strcmp(party->partyname, partyname) == 0)
153  return party;
154  }
155  return NULL;
156 }
157 
164 void party_remove(partylist *party) {
165  partylist *previousparty;
166  partylist **walk;
167  player *pl;
168 
169  previousparty = NULL;
170  for (walk = &firstparty; *walk != NULL; walk = &(*walk)->next) {
171  if (*walk == party) {
172  if (party == lastparty)
173  lastparty = previousparty;
174  *walk = party->next;
175  for (pl = first_player; pl != NULL; pl = pl->next) {
176  if (pl->party == party)
177  pl->party = NULL;
178  }
179  free(party->partyleader);
180  free(party->partyname);
181  free(party);
182  return;
183  }
184  previousparty = *walk;
185  }
186  LOG(llevError, "party_remove: I was asked to remove party %s, but it could not be found.\n",
187  party->partyname);
188 }
189 
197  return firstparty;
198 }
199 
209  return party->next;
210 }
211 
216  partylist *party;
217  partylist *next;
218  for (party = firstparty; party != NULL; party = next) {
219  next = party->next;
220  remove_if_unused(party);
221  }
222 }
223 
232 const char *party_get_password(const partylist *party) {
233  return party->passwd;
234 }
235 
244 void party_set_password(partylist *party, const char *password) {
245  strlcpy(party->passwd, password, sizeof(party->passwd));
247 }
248 
259 int party_confirm_password(const partylist *party, const char *password) {
260  return strcmp(party->passwd, password) == 0;
261 }
262 
274 void party_send_message(object *op, const char *message) {
275  player * const self = op->contr;
276  partylist * const party = self->party;
277 
278  for (player *pl = first_player; pl != NULL; pl = pl->next)
279  if (pl->party == party && pl != self)
281  message);
282 }
283 
292 const char *party_get_leader(const partylist *party) {
293  return party->partyleader;
294 }
295 
296 #ifdef PARTY_KILL_LOG
297 
309 void party_add_kill(partylist *party, const char *killer, const char *dead, long exp) {
310  int i, pos;
311 
312  if (party->kills >= PARTY_KILL_LOG) {
313  pos = PARTY_KILL_LOG-1;
314  for (i = 0; i < PARTY_KILL_LOG-1; i++)
315  memcpy(&(party->party_kills[i]), &(party->party_kills[i+1]), sizeof(party->party_kills[0]));
316  } else
317  pos = party->kills;
318  party->kills++;
319  party->total_exp += exp;
320  party->party_kills[pos].exp = exp;
321  strncpy(party->party_kills[pos].killer, killer, MAX_NAME);
322  strncpy(party->party_kills[pos].dead, dead, MAX_NAME);
323  party->party_kills[pos].killer[MAX_NAME] = 0;
324  party->party_kills[pos].dead[MAX_NAME] = 0;
325 }
326 #endif
give.next
def next
Definition: give.py:44
global.h
first_player
player * first_player
Definition: init.cpp:106
MSG_TYPE_COMMAND_SUCCESS
#define MSG_TYPE_COMMAND_SUCCESS
Definition: newclient.h:519
llevError
@ llevError
Definition: logger.h:11
partylist::next
partylist * next
Definition: party.h:13
party_leave
void party_leave(object *op)
Definition: party.cpp:123
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:51
player
Definition: player.h:105
strdup_local
#define strdup_local
Definition: compat.h:29
party_join
void party_join(object *op, partylist *party)
Definition: party.cpp:85
lastparty
static partylist * lastparty
Definition: party.cpp:27
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
MSG_TYPE_COMMAND_ERROR
#define MSG_TYPE_COMMAND_ERROR
Definition: newclient.h:518
partylist
Definition: party.h:10
buf
StringBuffer * buf
Definition: readable.cpp:1552
MSG_TYPE_COMMAND
#define MSG_TYPE_COMMAND
Definition: newclient.h:393
draw_ext_info
vs only yadda is in because all tags get reset on the next draw_ext_info In the second since it is all in one draw_ext_info
Definition: media-tags.txt:61
partylist::partyleader
char * partyleader
Definition: party.h:11
partylist::passwd
char passwd[9]
Definition: party.h:12
firstparty
static partylist * firstparty
Definition: party.cpp:26
message
TIPS on SURVIVING Crossfire is populated with a wealth of different monsters These monsters can have varying immunities and attack types In some of them can be quite a bit smarter than others It will be important for new players to learn the abilities of different monsters and learn just how much it will take to kill them This section discusses how monsters can interact with players Most monsters in the game are out to mindlessly kill and destroy the players These monsters will help boost a player s after he kills them When fighting a large amount of monsters in a single attempt to find a narrower hallway so that you are not being attacked from all sides Charging into a room full of Beholders for instance would not be open the door and fight them one at a time For there are several maps designed for them Find these areas and clear them out All throughout these a player can find signs and books which they can read by stepping onto them and hitting A to apply the book sign These messages will help the player to learn the system One more always keep an eye on your food If your food drops to your character will soon so BE CAREFUL ! NPCs Non Player Character are special monsters which have intelligence Players may be able to interact with these monsters to help solve puzzles and find items of interest To speak with a monster you suspect to be a simply move to an adjacent square to them and push the double ie Enter your message
Definition: survival-guide.txt:34
MAX_NAME
#define MAX_NAME
Definition: define.h:41
party_form
partylist * party_form(object *op, const char *partyname)
Definition: party.cpp:40
sproto.h
partylist::partyname
char * partyname
Definition: party.h:14
MAX_BUF
#define MAX_BUF
Definition: define.h:35
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.cpp:222
party_get_first
partylist * party_get_first(void)
Definition: party.cpp:196
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:251
party_remove
void party_remove(partylist *party)
Definition: party.cpp:164
give.op
op
Definition: give.py:33
NDI_WHITE
#define NDI_WHITE
Definition: newclient.h:232
party_get_password
const char * party_get_password(const partylist *party)
Definition: party.cpp:232
party_send_message
void party_send_message(object *op, const char *message)
Definition: party.cpp:274
MSG_TYPE_COMMUNICATION_PARTY
#define MSG_TYPE_COMMUNICATION_PARTY
Definition: newclient.h:616
party_confirm_password
int party_confirm_password(const partylist *party, const char *password)
Definition: party.cpp:259
party_set_password
void party_set_password(partylist *party, const char *password)
Definition: party.cpp:244
party_find
partylist * party_find(const char *partyname)
Definition: party.cpp:148
party_get_leader
const char * party_get_leader(const partylist *party)
Definition: party.cpp:292
MSG_TYPE_COMMUNICATION
#define MSG_TYPE_COMMUNICATION
Definition: newclient.h:399
reputation.killer
def killer
Definition: reputation.py:13
party_obsolete_parties
void party_obsolete_parties(void)
Definition: party.cpp:215
remove_if_unused
static void remove_if_unused(partylist *party)
Definition: party.cpp:108
party_get_next
partylist * party_get_next(const partylist *party)
Definition: party.cpp:208
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
replace_unprintable_chars
void replace_unprintable_chars(char *buf)
Definition: utils.cpp:447