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.5 by root, Tue Sep 12 19:20:08 2006 UTC vs.
Revision 1.19 by root, Mon May 28 21:28:35 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines