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.7 by root, Fri Nov 17 21:26:42 2006 UTC vs.
Revision 1.18 by root, Thu May 17 14:14:55 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines