ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_party.C
(Generate patch)

Comparing deliantra/server/server/c_party.C (file contents):
Revision 1.6 by root, Thu Sep 14 22:34:03 2006 UTC vs.
Revision 1.20 by root, Sun Jul 1 05:00:19 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#ifndef __CEXTRACT__
26# include <sproto.h> 25#include <sproto.h>
27#endif
28#include <spells.h> 26#include <spells.h>
29
30#ifdef COZY_SERVER
31// used for pet monster logic etc.
32int
33same_party (partylist *a, partylist *b)
34{
35 return a == b && a;
36}
37#endif
38 27
39static partylist *firstparty = NULL; /* Keeps track of first party in list */ 28static partylist *firstparty = NULL; /* Keeps track of first party in list */
40static partylist *lastparty = NULL; /*Keeps track of last party in list */ 29static partylist *lastparty = NULL; /*Keeps track of last party in list */
41 30
42partylist * 31partylist *
54form_party (object *op, const char *params) 43form_party (object *op, const char *params)
55{ 44{
56 partylist *newparty; 45 partylist *newparty;
57 46
58 newparty = (partylist *) malloc (sizeof (partylist)); 47 newparty = (partylist *) malloc (sizeof (partylist));
59 newparty->partyname = strdup_local (params); 48 newparty->partyname = strdup (params);
60 newparty->total_exp = 0; 49 newparty->total_exp = 0;
61 newparty->kills = 0; 50 newparty->kills = 0;
62 newparty->passwd[0] = '\0'; 51 newparty->passwd[0] = '\0';
63 newparty->next = NULL; 52 newparty->next = NULL;
64 newparty->partyleader = strdup_local (op->name); 53 newparty->partyleader = strdup (op->name);
65 new_draw_info_format (NDI_UNIQUE, 0, op, "You have formed party: %s", newparty->partyname); 54 new_draw_info_format (NDI_UNIQUE, 0, op, "You have formed party: %s", newparty->partyname);
66 op->contr->party = newparty; 55 op->contr->party = newparty;
67 56
68 return newparty; 57 return newparty;
69} 58}
72remove_party (partylist *target_party) 61remove_party (partylist *target_party)
73{ 62{
74 partylist *tmpparty; 63 partylist *tmpparty;
75 partylist *previousparty; 64 partylist *previousparty;
76 partylist *nextparty; 65 partylist *nextparty;
77 player *pl;
78 66
79 if (firstparty == NULL) 67 if (firstparty == NULL)
80 { 68 {
81 LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); 69 LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname);
82 return; 70 return;
83 } 71 }
84 72
85 for (pl = first_player; pl != NULL; pl = pl->next) 73 for_all_players (pl)
86 if (pl->party == target_party) 74 if (pl->party == target_party)
87 pl->party = NULL; 75 pl->party = NULL;
88 76
89 /* special case-ism for parties at the beginning and end of the list */ 77 /* special case-ism for parties at the beginning and end of the list */
90 if (target_party == firstparty) 78 if (target_party == firstparty)
140/* Remove unused parties, this could be made to scale a lot better. */ 128/* Remove unused parties, this could be made to scale a lot better. */
141void 129void
142obsolete_parties (void) 130obsolete_parties (void)
143{ 131{
144 int player_count; 132 int player_count;
145 player *pl;
146 partylist *party; 133 partylist *party;
147 partylist *next = NULL; 134 partylist *next = NULL;
148 135
149 if (!firstparty) 136 if (!firstparty)
150 return; /* we can't obsolete parties if there aren't any */ 137 return; /* we can't obsolete parties if there aren't any */
151 for (party = firstparty; party != NULL; party = next) 138 for (party = firstparty; party != NULL; party = next)
152 { 139 {
153 next = party->next; 140 next = party->next;
154 player_count = 0; 141 player_count = 0;
155 for (pl = first_player; pl != NULL; pl = pl->next) 142 for_all_players (pl)
156 if (pl->party == party) 143 if (pl->party == party)
157 player_count++; 144 player_count++;
158 if (player_count == 0) 145 if (player_count == 0)
159 remove_party (party); 146 remove_party (party);
160 } 147 }
161} 148}
162 149
163#ifdef PARTY_KILL_LOG
164void 150void
165add_kill_to_party (partylist *party, char *killer, char *dead, long exp) 151add_kill_to_party (partylist *party, const char *killer, const char *dead, long exp)
166{ 152{
167 int i, pos; 153 int i, pos;
168 154
169 if (party == NULL) 155 if (party == NULL)
170 return; 156 return;
157
171 if (party->kills >= PARTY_KILL_LOG) 158 if (party->kills >= PARTY_KILL_LOG)
172 { 159 {
173 pos = PARTY_KILL_LOG - 1; 160 pos = PARTY_KILL_LOG - 1;
174 for (i = 0; i < PARTY_KILL_LOG - 1; i++) 161 for (i = 0; i < PARTY_KILL_LOG - 1; i++)
175 party->party_kills[i] = party->party_kills[i + 1]; 162 party->party_kills[i] = party->party_kills[i + 1];
176 } 163 }
177 else 164 else
178 pos = party->kills; 165 pos = party->kills;
166
179 party->kills++; 167 party->kills++;
180 party->total_exp += exp; 168 party->total_exp += exp;
181 party->party_kills[pos].exp = exp; 169 party->party_kills[pos].exp = exp;
182 assign (party->party_kills[pos].killer, killer); 170 assign (party->party_kills[pos].killer, killer);
183 assign (party->party_kills[pos].dead, dead); 171 assign (party->party_kills[pos].dead, dead);
184 party->party_kills[pos].killer[MAX_NAME] = 0; 172 party->party_kills[pos].killer[MAX_NAME] = 0;
185 party->party_kills[pos].dead[MAX_NAME] = 0; 173 party->party_kills[pos].dead[MAX_NAME] = 0;
186} 174}
187#endif
188 175
189int 176int
190confirm_party_password (object *op) 177confirm_party_password (object *op)
191{ 178{
192 partylist *tmppartylist; 179 partylist *tmppartylist;
216 op->contr->party = op->contr->party_to_join; 203 op->contr->party = op->contr->party_to_join;
217 op->contr->party_to_join = NULL; 204 op->contr->party_to_join = NULL;
218 new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s\n", joined_party->partyname); 205 new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s\n", joined_party->partyname);
219 snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, joined_party->partyname); 206 snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, joined_party->partyname);
220 send_party_message (op, buf); 207 send_party_message (op, buf);
221 op->contr->state = ST_PLAYING; 208 op->contr->ns->state = ST_PLAYING;
222 return; 209 return;
223 } 210 }
224 else 211 else
225 { 212 {
226 new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password"); 213 new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password");
227 op->contr->party_to_join = NULL; 214 op->contr->party_to_join = NULL;
228 op->contr->state = ST_PLAYING; 215 op->contr->ns->state = ST_PLAYING;
229 return; 216 return;
230 } 217 }
231} 218}
232 219
233void 220void
234send_party_message (object *op, char *msg) 221send_party_message (object *op, char *msg)
235{ 222{
236 player *pl; 223 for_all_players (pl)
237
238 for (pl = first_player; pl != NULL; pl = pl->next)
239 if (pl->ob->contr->party == op->contr->party && pl->ob != op) 224 if (pl->ob->contr->party == op->contr->party && pl->ob != op)
240 new_draw_info (NDI_WHITE, 0, pl->ob, msg); 225 new_draw_info (NDI_WHITE, 0, pl->ob, msg);
241} 226}
242 227
243int 228int
245{ 230{
246 char party_params[MAX_BUF]; 231 char party_params[MAX_BUF];
247 232
248 if (!params) 233 if (!params)
249 return 0; 234 return 0;
235
250 strcpy (party_params, "say "); 236 strcpy (party_params, "say ");
251 strcat (party_params, params); 237 strcat (party_params, params);
252 command_party (op, party_params); 238 command_party (op, party_params);
253 return 0; 239 return 0;
254} 240}
255 241
256
257int 242int
258command_party (object *op, char *params) 243command_party (object *op, char *params)
259{ 244{
260 char buf[MAX_BUF]; 245 char buf[MAX_BUF];
261 partylist *tmpparty, *oldparty; /* For iterating over linked list */ 246 partylist *tmpparty, *oldparty; /* For iterating over linked list */
273 currentparty = op->contr->party->partyname; 258 currentparty = op->contr->party->partyname;
274 new_draw_info_format (NDI_UNIQUE, 0, op, "You are a member of party %s.", currentparty); 259 new_draw_info_format (NDI_UNIQUE, 0, op, "You are a member of party %s.", currentparty);
275 } 260 }
276 return 1; 261 return 1;
277 } 262 }
263
278 if (strcmp (params, "help") == 0) 264 if (strcmp (params, "help") == 0)
279 { 265 {
280 new_draw_info (NDI_UNIQUE, 0, op, "To form a party type: party form <partyname>"); 266 new_draw_info (NDI_UNIQUE, 0, op, "To form a party type: party form <partyname>");
281 new_draw_info (NDI_UNIQUE, 0, op, "To join a party type: party join <partyname>"); 267 new_draw_info (NDI_UNIQUE, 0, op, "To join a party type: party join <partyname>");
282 new_draw_info (NDI_UNIQUE, 0, op, "If the party has a passwd, it will you prompt you for it."); 268 new_draw_info (NDI_UNIQUE, 0, op, "If the party has a passwd, it will you prompt you for it.");
284 new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave"); 270 new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave");
285 new_draw_info (NDI_UNIQUE, 0, op, "To change a passwd for a party type: party passwd <password>"); 271 new_draw_info (NDI_UNIQUE, 0, op, "To change a passwd for a party type: party passwd <password>");
286 new_draw_info (NDI_UNIQUE, 0, op, "There is an 8 character max"); 272 new_draw_info (NDI_UNIQUE, 0, op, "There is an 8 character max");
287 new_draw_info (NDI_UNIQUE, 0, op, "To talk to party members type: party say <msg>"); 273 new_draw_info (NDI_UNIQUE, 0, op, "To talk to party members type: party say <msg>");
288 new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who"); 274 new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who");
289#ifdef PARTY_KILL_LOG
290 new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills"); 275 new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills");
291#endif
292 return 1; 276 return 1;
293 } 277 }
294#ifdef PARTY_KILL_LOG 278
295 if (!strncmp (params, "kills", 5)) 279 if (!strncmp (params, "kills", 5))
296 { 280 {
297 int i, max; 281 int i, max;
298 char chr; 282 char chr;
299 char buffer[80]; 283 char buffer[80];
347 new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); 331 new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------");
348 sprintf (buffer, "Totals: %d kills, %.1f%c exp", tmpparty->kills, exp, chr); 332 sprintf (buffer, "Totals: %d kills, %.1f%c exp", tmpparty->kills, exp, chr);
349 new_draw_info (NDI_UNIQUE, 0, op, buffer); 333 new_draw_info (NDI_UNIQUE, 0, op, buffer);
350 return 1; 334 return 1;
351 } 335 }
352#endif /* PARTY_KILL_LOG */ 336
353 if (strncmp (params, "say ", 4) == 0) 337 if (strncmp (params, "say ", 4) == 0)
354 { 338 {
355 if (op->contr->party == NULL) 339 if (op->contr->party == NULL)
356 { 340 {
357 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); 341 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party.");
359 } 343 }
360 params += 4; 344 params += 4;
361 currentparty = op->contr->party->partyname; 345 currentparty = op->contr->party->partyname;
362 snprintf (buf, MAX_BUF - 1, "[%s] %s says: %s", currentparty, &op->name, params); 346 snprintf (buf, MAX_BUF - 1, "[%s] %s says: %s", currentparty, &op->name, params);
363 send_party_message (op, buf); 347 send_party_message (op, buf);
364 new_draw_info_format (NDI_WHITE, 0, op, "[%s] You say: %s", currentparty, params); 348 new_draw_info_format (NDI_LT_GREEN | NDI_UNIQUE, 0, op, "[%s] You say: %s", currentparty, params);
365 return 1; 349 return 1;
366 } 350 }
367 351
368 if (strncmp (params, "form ", 5) == 0) 352 if (strncmp (params, "form ", 5) == 0)
369 { 353 {
370 int player_count; 354 int player_count;
371 player *pl;
372 355
373 params += 5; 356 params += 5;
374 if (op->contr->party) 357 if (op->contr->party)
375 oldparty = op->contr->party; 358 oldparty = op->contr->party;
376 else 359 else
399 * it, so check if there are any other members and if not, delete the party 382 * it, so check if there are any other members and if not, delete the party
400 */ 383 */
401 player_count = 0; 384 player_count = 0;
402 if (oldparty) 385 if (oldparty)
403 { 386 {
404 for (pl = first_player; pl->next != NULL; pl = pl->next) 387 for_all_players (pl)
405 {
406 if (pl->party == oldparty) 388 if (pl->party == oldparty)
407 player_count++; 389 player_count++;
408 } 390
409 if (player_count == 0) 391 if (player_count == 0)
410 remove_party (oldparty); 392 remove_party (oldparty);
411 } 393 }
394
412 return 0; 395 return 0;
413 } /* form */ 396 } /* form */
414 397
415 if (strcmp (params, "leave") == 0) 398 if (strcmp (params, "leave") == 0)
416 { 399 {
424 sprintf (buf, "%s leaves party %s.", &op->name, currentparty); 407 sprintf (buf, "%s leaves party %s.", &op->name, currentparty);
425 send_party_message (op, buf); 408 send_party_message (op, buf);
426 op->contr->party = NULL; 409 op->contr->party = NULL;
427 return 1; 410 return 1;
428 } 411 }
412
429 if (strcmp (params, "who") == 0) 413 if (strcmp (params, "who") == 0)
430 { 414 {
431 player *pl;
432
433 tmpparty = op->contr->party; 415 tmpparty = op->contr->party;
434 if (op->contr->party == NULL) 416 if (op->contr->party == NULL)
435 { 417 {
436 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); 418 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party.");
437 return 1; 419 return 1;
438 } 420 }
439 new_draw_info_format (NDI_UNIQUE, 0, op, "Members of party: %s.", op->contr->party->partyname); 421 new_draw_info_format (NDI_UNIQUE, 0, op, "Members of party: %s.", op->contr->party->partyname);
440 for (pl = first_player; pl != NULL; pl = pl->next) 422 for_all_players (pl)
441 if (pl->ob->contr->party == op->contr->party) 423 if (pl->ob->contr->party == op->contr->party)
442 { 424 {
443 if (settings.set_title == TRUE) 425 if (settings.set_title == TRUE)
444 { 426 {
445 if (pl->ob->contr->own_title[0] != '\0') 427 if (pl->ob->contr->own_title[0] != '\0')
597 new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave"); 579 new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave");
598 new_draw_info (NDI_UNIQUE, 0, op, "To change a passwd for a party type: party passwd <password>"); 580 new_draw_info (NDI_UNIQUE, 0, op, "To change a passwd for a party type: party passwd <password>");
599 new_draw_info (NDI_UNIQUE, 0, op, "There is an 8 character max"); 581 new_draw_info (NDI_UNIQUE, 0, op, "There is an 8 character max");
600 new_draw_info (NDI_UNIQUE, 0, op, "To talk to party members type: party say <msg>"); 582 new_draw_info (NDI_UNIQUE, 0, op, "To talk to party members type: party say <msg>");
601 new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who"); 583 new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who");
602#ifdef PARTY_KILL_LOG
603 new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills"); 584 new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills");
604#endif
605 return 1; 585 return 1;
606} 586}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines