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.4 by root, Sat Sep 9 22:54:31 2006 UTC vs.
Revision 1.16 by pippijn, Thu Mar 1 12:28:16 2007 UTC

1
2/* 1/*
3 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
4 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 7 *
8 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
9 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
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) 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,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License 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
19 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 at <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 28
31#ifdef COZY_SERVER 29#ifdef COZY_SERVER
32// used for pet monster logic etc. 30// used for pet monster logic etc.
33int 31int
55form_party (object *op, const char *params) 53form_party (object *op, const char *params)
56{ 54{
57 partylist *newparty; 55 partylist *newparty;
58 56
59 newparty = (partylist *) malloc (sizeof (partylist)); 57 newparty = (partylist *) malloc (sizeof (partylist));
60 newparty->partyname = strdup_local (params); 58 newparty->partyname = strdup (params);
61 newparty->total_exp = 0; 59 newparty->total_exp = 0;
62 newparty->kills = 0; 60 newparty->kills = 0;
63 newparty->passwd[0] = '\0'; 61 newparty->passwd[0] = '\0';
64 newparty->next = NULL; 62 newparty->next = NULL;
65 newparty->partyleader = strdup_local (op->name); 63 newparty->partyleader = strdup (op->name);
66 new_draw_info_format (NDI_UNIQUE, 0, op, "You have formed party: %s", newparty->partyname); 64 new_draw_info_format (NDI_UNIQUE, 0, op, "You have formed party: %s", newparty->partyname);
67 op->contr->party = newparty; 65 op->contr->party = newparty;
68 66
69 return newparty; 67 return newparty;
70} 68}
73remove_party (partylist *target_party) 71remove_party (partylist *target_party)
74{ 72{
75 partylist *tmpparty; 73 partylist *tmpparty;
76 partylist *previousparty; 74 partylist *previousparty;
77 partylist *nextparty; 75 partylist *nextparty;
78 player *pl;
79 76
80 if (firstparty == NULL) 77 if (firstparty == NULL)
81 { 78 {
82 LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); 79 LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname);
83 return; 80 return;
84 } 81 }
85 82
86 for (pl = first_player; pl != NULL; pl = pl->next) 83 for_all_players (pl)
87 if (pl->party == target_party) 84 if (pl->party == target_party)
88 pl->party = NULL; 85 pl->party = NULL;
89 86
90 /* special case-ism for parties at the beginning and end of the list */ 87 /* special case-ism for parties at the beginning and end of the list */
91 if (target_party == firstparty) 88 if (target_party == firstparty)
141/* Remove unused parties, this could be made to scale a lot better. */ 138/* Remove unused parties, this could be made to scale a lot better. */
142void 139void
143obsolete_parties (void) 140obsolete_parties (void)
144{ 141{
145 int player_count; 142 int player_count;
146 player *pl;
147 partylist *party; 143 partylist *party;
148 partylist *next = NULL; 144 partylist *next = NULL;
149 145
150 if (!firstparty) 146 if (!firstparty)
151 return; /* we can't obsolete parties if there aren't any */ 147 return; /* we can't obsolete parties if there aren't any */
152 for (party = firstparty; party != NULL; party = next) 148 for (party = firstparty; party != NULL; party = next)
153 { 149 {
154 next = party->next; 150 next = party->next;
155 player_count = 0; 151 player_count = 0;
156 for (pl = first_player; pl != NULL; pl = pl->next) 152 for_all_players (pl)
157 if (pl->party == party) 153 if (pl->party == party)
158 player_count++; 154 player_count++;
159 if (player_count == 0) 155 if (player_count == 0)
160 remove_party (party); 156 remove_party (party);
161 } 157 }
162} 158}
163 159
164#ifdef PARTY_KILL_LOG
165void 160void
166add_kill_to_party (partylist *party, char *killer, char *dead, long exp) 161add_kill_to_party (partylist *party, char *killer, char *dead, long exp)
167{ 162{
168 int i, pos; 163 int i, pos;
169 164
170 if (party == NULL) 165 if (party == NULL)
171 return; 166 return;
167
172 if (party->kills >= PARTY_KILL_LOG) 168 if (party->kills >= PARTY_KILL_LOG)
173 { 169 {
174 pos = PARTY_KILL_LOG - 1; 170 pos = PARTY_KILL_LOG - 1;
175 for (i = 0; i < PARTY_KILL_LOG - 1; i++) 171 for (i = 0; i < PARTY_KILL_LOG - 1; i++)
176 party->party_kills[i] = party->party_kills[i + 1]; 172 party->party_kills[i] = party->party_kills[i + 1];
177 } 173 }
178 else 174 else
179 pos = party->kills; 175 pos = party->kills;
176
180 party->kills++; 177 party->kills++;
181 party->total_exp += exp; 178 party->total_exp += exp;
182 party->party_kills[pos].exp = exp; 179 party->party_kills[pos].exp = exp;
183 strncpy (party->party_kills[pos].killer, killer, MAX_NAME); 180 assign (party->party_kills[pos].killer, killer);
184 strncpy (party->party_kills[pos].dead, dead, MAX_NAME); 181 assign (party->party_kills[pos].dead, dead);
185 party->party_kills[pos].killer[MAX_NAME] = 0; 182 party->party_kills[pos].killer[MAX_NAME] = 0;
186 party->party_kills[pos].dead[MAX_NAME] = 0; 183 party->party_kills[pos].dead[MAX_NAME] = 0;
187} 184}
188#endif
189 185
190int 186int
191confirm_party_password (object *op) 187confirm_party_password (object *op)
192{ 188{
193 partylist *tmppartylist; 189 partylist *tmppartylist;
217 op->contr->party = op->contr->party_to_join; 213 op->contr->party = op->contr->party_to_join;
218 op->contr->party_to_join = NULL; 214 op->contr->party_to_join = NULL;
219 new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s\n", joined_party->partyname); 215 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); 216 snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, joined_party->partyname);
221 send_party_message (op, buf); 217 send_party_message (op, buf);
222 op->contr->state = ST_PLAYING; 218 op->contr->ns->state = ST_PLAYING;
223 return; 219 return;
224 } 220 }
225 else 221 else
226 { 222 {
227 new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password"); 223 new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password");
228 op->contr->party_to_join = NULL; 224 op->contr->party_to_join = NULL;
229 op->contr->state = ST_PLAYING; 225 op->contr->ns->state = ST_PLAYING;
230 return; 226 return;
231 } 227 }
232} 228}
233 229
234void 230void
235send_party_message (object *op, char *msg) 231send_party_message (object *op, char *msg)
236{ 232{
237 player *pl; 233 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) 234 if (pl->ob->contr->party == op->contr->party && pl->ob != op)
241 new_draw_info (NDI_WHITE, 0, pl->ob, msg); 235 new_draw_info (NDI_WHITE, 0, pl->ob, msg);
242} 236}
243 237
244int 238int
246{ 240{
247 char party_params[MAX_BUF]; 241 char party_params[MAX_BUF];
248 242
249 if (!params) 243 if (!params)
250 return 0; 244 return 0;
245
251 strcpy (party_params, "say "); 246 strcpy (party_params, "say ");
252 strcat (party_params, params); 247 strcat (party_params, params);
253 command_party (op, party_params); 248 command_party (op, party_params);
254 return 0; 249 return 0;
255} 250}
256 251
257
258int 252int
259command_party (object *op, char *params) 253command_party (object *op, char *params)
260{ 254{
261 char buf[MAX_BUF]; 255 char buf[MAX_BUF];
262 partylist *tmpparty, *oldparty; /* For iterating over linked list */ 256 partylist *tmpparty, *oldparty; /* For iterating over linked list */
274 currentparty = op->contr->party->partyname; 268 currentparty = op->contr->party->partyname;
275 new_draw_info_format (NDI_UNIQUE, 0, op, "You are a member of party %s.", currentparty); 269 new_draw_info_format (NDI_UNIQUE, 0, op, "You are a member of party %s.", currentparty);
276 } 270 }
277 return 1; 271 return 1;
278 } 272 }
273
279 if (strcmp (params, "help") == 0) 274 if (strcmp (params, "help") == 0)
280 { 275 {
281 new_draw_info (NDI_UNIQUE, 0, op, "To form a party type: party form <partyname>"); 276 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>"); 277 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."); 278 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"); 280 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>"); 281 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"); 282 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>"); 283 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"); 284 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"); 285 new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills");
292#endif
293 return 1; 286 return 1;
294 } 287 }
295#ifdef PARTY_KILL_LOG 288
296 if (!strncmp (params, "kills", 5)) 289 if (!strncmp (params, "kills", 5))
297 { 290 {
298 int i, max; 291 int i, max;
299 char chr; 292 char chr;
300 char buffer[80]; 293 char buffer[80];
348 new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); 341 new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------");
349 sprintf (buffer, "Totals: %d kills, %.1f%c exp", tmpparty->kills, exp, chr); 342 sprintf (buffer, "Totals: %d kills, %.1f%c exp", tmpparty->kills, exp, chr);
350 new_draw_info (NDI_UNIQUE, 0, op, buffer); 343 new_draw_info (NDI_UNIQUE, 0, op, buffer);
351 return 1; 344 return 1;
352 } 345 }
353#endif /* PARTY_KILL_LOG */ 346
354 if (strncmp (params, "say ", 4) == 0) 347 if (strncmp (params, "say ", 4) == 0)
355 { 348 {
356 if (op->contr->party == NULL) 349 if (op->contr->party == NULL)
357 { 350 {
358 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); 351 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party.");
360 } 353 }
361 params += 4; 354 params += 4;
362 currentparty = op->contr->party->partyname; 355 currentparty = op->contr->party->partyname;
363 snprintf (buf, MAX_BUF - 1, "[%s] %s says: %s", currentparty, &op->name, params); 356 snprintf (buf, MAX_BUF - 1, "[%s] %s says: %s", currentparty, &op->name, params);
364 send_party_message (op, buf); 357 send_party_message (op, buf);
365 new_draw_info_format (NDI_WHITE, 0, op, "[%s] You say: %s", currentparty, params); 358 new_draw_info_format (NDI_LT_GREEN | NDI_UNIQUE, 0, op, "[%s] You say: %s", currentparty, params);
366 return 1; 359 return 1;
367 } 360 }
368 361
369 if (strncmp (params, "form ", 5) == 0) 362 if (strncmp (params, "form ", 5) == 0)
370 { 363 {
371 int player_count; 364 int player_count;
372 player *pl;
373 365
374 params += 5; 366 params += 5;
375 if (op->contr->party) 367 if (op->contr->party)
376 oldparty = op->contr->party; 368 oldparty = op->contr->party;
377 else 369 else
400 * it, so check if there are any other members and if not, delete the party 392 * it, so check if there are any other members and if not, delete the party
401 */ 393 */
402 player_count = 0; 394 player_count = 0;
403 if (oldparty) 395 if (oldparty)
404 { 396 {
405 for (pl = first_player; pl->next != NULL; pl = pl->next) 397 for_all_players (pl)
406 {
407 if (pl->party == oldparty) 398 if (pl->party == oldparty)
408 player_count++; 399 player_count++;
409 } 400
410 if (player_count == 0) 401 if (player_count == 0)
411 remove_party (oldparty); 402 remove_party (oldparty);
412 } 403 }
404
413 return 0; 405 return 0;
414 } /* form */ 406 } /* form */
415 407
416 if (strcmp (params, "leave") == 0) 408 if (strcmp (params, "leave") == 0)
417 { 409 {
425 sprintf (buf, "%s leaves party %s.", &op->name, currentparty); 417 sprintf (buf, "%s leaves party %s.", &op->name, currentparty);
426 send_party_message (op, buf); 418 send_party_message (op, buf);
427 op->contr->party = NULL; 419 op->contr->party = NULL;
428 return 1; 420 return 1;
429 } 421 }
422
430 if (strcmp (params, "who") == 0) 423 if (strcmp (params, "who") == 0)
431 { 424 {
432 player *pl;
433
434 tmpparty = op->contr->party; 425 tmpparty = op->contr->party;
435 if (op->contr->party == NULL) 426 if (op->contr->party == NULL)
436 { 427 {
437 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); 428 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party.");
438 return 1; 429 return 1;
439 } 430 }
440 new_draw_info_format (NDI_UNIQUE, 0, op, "Members of party: %s.", op->contr->party->partyname); 431 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) 432 for_all_players (pl)
442 if (pl->ob->contr->party == op->contr->party) 433 if (pl->ob->contr->party == op->contr->party)
443 { 434 {
444 if (settings.set_title == TRUE) 435 if (settings.set_title == TRUE)
445 { 436 {
446 if (pl->ob->contr->own_title[0] != '\0') 437 if (pl->ob->contr->own_title[0] != '\0')
598 new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave"); 589 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>"); 590 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"); 591 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>"); 592 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"); 593 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"); 594 new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills");
605#endif
606 return 1; 595 return 1;
607} 596}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines