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.20 by root, Sun Jul 1 05:00:19 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
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 3 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, see <http://www.gnu.org/licenses/>.
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
21 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22 The authors can be reached via e-mail at crossfire-devel@real-time.com
23*/ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#ifndef __CEXTRACT__
27# include <sproto.h> 25#include <sproto.h>
28#endif
29#include <spells.h> 26#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 27
40static partylist *firstparty = NULL; /* Keeps track of first party in list */ 28static partylist *firstparty = NULL; /* Keeps track of first party in list */
41static partylist *lastparty = NULL; /*Keeps track of last party in list */ 29static partylist *lastparty = NULL; /*Keeps track of last party in list */
42 30
43partylist * 31partylist *
55form_party (object *op, const char *params) 43form_party (object *op, const char *params)
56{ 44{
57 partylist *newparty; 45 partylist *newparty;
58 46
59 newparty = (partylist *) malloc (sizeof (partylist)); 47 newparty = (partylist *) malloc (sizeof (partylist));
60 newparty->partyname = strdup_local (params); 48 newparty->partyname = strdup (params);
61 newparty->total_exp = 0; 49 newparty->total_exp = 0;
62 newparty->kills = 0; 50 newparty->kills = 0;
63 newparty->passwd[0] = '\0'; 51 newparty->passwd[0] = '\0';
64 newparty->next = NULL; 52 newparty->next = NULL;
65 newparty->partyleader = strdup_local (op->name); 53 newparty->partyleader = strdup (op->name);
66 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);
67 op->contr->party = newparty; 55 op->contr->party = newparty;
68 56
69 return newparty; 57 return newparty;
70} 58}
73remove_party (partylist *target_party) 61remove_party (partylist *target_party)
74{ 62{
75 partylist *tmpparty; 63 partylist *tmpparty;
76 partylist *previousparty; 64 partylist *previousparty;
77 partylist *nextparty; 65 partylist *nextparty;
78 player *pl;
79 66
80 if (firstparty == NULL) 67 if (firstparty == NULL)
81 { 68 {
82 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);
83 return; 70 return;
84 } 71 }
85 72
86 for (pl = first_player; pl != NULL; pl = pl->next) 73 for_all_players (pl)
87 if (pl->party == target_party) 74 if (pl->party == target_party)
88 pl->party = NULL; 75 pl->party = NULL;
89 76
90 /* 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 */
91 if (target_party == firstparty) 78 if (target_party == firstparty)
141/* 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. */
142void 129void
143obsolete_parties (void) 130obsolete_parties (void)
144{ 131{
145 int player_count; 132 int player_count;
146 player *pl;
147 partylist *party; 133 partylist *party;
148 partylist *next = NULL; 134 partylist *next = NULL;
149 135
150 if (!firstparty) 136 if (!firstparty)
151 return; /* we can't obsolete parties if there aren't any */ 137 return; /* we can't obsolete parties if there aren't any */
152 for (party = firstparty; party != NULL; party = next) 138 for (party = firstparty; party != NULL; party = next)
153 { 139 {
154 next = party->next; 140 next = party->next;
155 player_count = 0; 141 player_count = 0;
156 for (pl = first_player; pl != NULL; pl = pl->next) 142 for_all_players (pl)
157 if (pl->party == party) 143 if (pl->party == party)
158 player_count++; 144 player_count++;
159 if (player_count == 0) 145 if (player_count == 0)
160 remove_party (party); 146 remove_party (party);
161 } 147 }
162} 148}
163 149
164#ifdef PARTY_KILL_LOG
165void 150void
166add_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)
167{ 152{
168 int i, pos; 153 int i, pos;
169 154
170 if (party == NULL) 155 if (party == NULL)
171 return; 156 return;
157
172 if (party->kills >= PARTY_KILL_LOG) 158 if (party->kills >= PARTY_KILL_LOG)
173 { 159 {
174 pos = PARTY_KILL_LOG - 1; 160 pos = PARTY_KILL_LOG - 1;
175 for (i = 0; i < PARTY_KILL_LOG - 1; i++) 161 for (i = 0; i < PARTY_KILL_LOG - 1; i++)
176 party->party_kills[i] = party->party_kills[i + 1]; 162 party->party_kills[i] = party->party_kills[i + 1];
177 } 163 }
178 else 164 else
179 pos = party->kills; 165 pos = party->kills;
166
180 party->kills++; 167 party->kills++;
181 party->total_exp += exp; 168 party->total_exp += exp;
182 party->party_kills[pos].exp = exp; 169 party->party_kills[pos].exp = exp;
183 assign (party->party_kills[pos].killer, killer); 170 assign (party->party_kills[pos].killer, killer);
184 assign (party->party_kills[pos].dead, dead); 171 assign (party->party_kills[pos].dead, dead);
185 party->party_kills[pos].killer[MAX_NAME] = 0; 172 party->party_kills[pos].killer[MAX_NAME] = 0;
186 party->party_kills[pos].dead[MAX_NAME] = 0; 173 party->party_kills[pos].dead[MAX_NAME] = 0;
187} 174}
188#endif
189 175
190int 176int
191confirm_party_password (object *op) 177confirm_party_password (object *op)
192{ 178{
193 partylist *tmppartylist; 179 partylist *tmppartylist;
217 op->contr->party = op->contr->party_to_join; 203 op->contr->party = op->contr->party_to_join;
218 op->contr->party_to_join = NULL; 204 op->contr->party_to_join = NULL;
219 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);
220 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);
221 send_party_message (op, buf); 207 send_party_message (op, buf);
222 op->contr->state = ST_PLAYING; 208 op->contr->ns->state = ST_PLAYING;
223 return; 209 return;
224 } 210 }
225 else 211 else
226 { 212 {
227 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");
228 op->contr->party_to_join = NULL; 214 op->contr->party_to_join = NULL;
229 op->contr->state = ST_PLAYING; 215 op->contr->ns->state = ST_PLAYING;
230 return; 216 return;
231 } 217 }
232} 218}
233 219
234void 220void
235send_party_message (object *op, char *msg) 221send_party_message (object *op, char *msg)
236{ 222{
237 player *pl; 223 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) 224 if (pl->ob->contr->party == op->contr->party && pl->ob != op)
241 new_draw_info (NDI_WHITE, 0, pl->ob, msg); 225 new_draw_info (NDI_WHITE, 0, pl->ob, msg);
242} 226}
243 227
244int 228int
246{ 230{
247 char party_params[MAX_BUF]; 231 char party_params[MAX_BUF];
248 232
249 if (!params) 233 if (!params)
250 return 0; 234 return 0;
235
251 strcpy (party_params, "say "); 236 strcpy (party_params, "say ");
252 strcat (party_params, params); 237 strcat (party_params, params);
253 command_party (op, party_params); 238 command_party (op, party_params);
254 return 0; 239 return 0;
255} 240}
256 241
257
258int 242int
259command_party (object *op, char *params) 243command_party (object *op, char *params)
260{ 244{
261 char buf[MAX_BUF]; 245 char buf[MAX_BUF];
262 partylist *tmpparty, *oldparty; /* For iterating over linked list */ 246 partylist *tmpparty, *oldparty; /* For iterating over linked list */
274 currentparty = op->contr->party->partyname; 258 currentparty = op->contr->party->partyname;
275 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);
276 } 260 }
277 return 1; 261 return 1;
278 } 262 }
263
279 if (strcmp (params, "help") == 0) 264 if (strcmp (params, "help") == 0)
280 { 265 {
281 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>");
282 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>");
283 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.");
285 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");
286 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>");
287 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");
288 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>");
289 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");
290#ifdef PARTY_KILL_LOG
291 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");
292#endif
293 return 1; 276 return 1;
294 } 277 }
295#ifdef PARTY_KILL_LOG 278
296 if (!strncmp (params, "kills", 5)) 279 if (!strncmp (params, "kills", 5))
297 { 280 {
298 int i, max; 281 int i, max;
299 char chr; 282 char chr;
300 char buffer[80]; 283 char buffer[80];
348 new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); 331 new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------");
349 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);
350 new_draw_info (NDI_UNIQUE, 0, op, buffer); 333 new_draw_info (NDI_UNIQUE, 0, op, buffer);
351 return 1; 334 return 1;
352 } 335 }
353#endif /* PARTY_KILL_LOG */ 336
354 if (strncmp (params, "say ", 4) == 0) 337 if (strncmp (params, "say ", 4) == 0)
355 { 338 {
356 if (op->contr->party == NULL) 339 if (op->contr->party == NULL)
357 { 340 {
358 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.");
360 } 343 }
361 params += 4; 344 params += 4;
362 currentparty = op->contr->party->partyname; 345 currentparty = op->contr->party->partyname;
363 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);
364 send_party_message (op, buf); 347 send_party_message (op, buf);
365 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);
366 return 1; 349 return 1;
367 } 350 }
368 351
369 if (strncmp (params, "form ", 5) == 0) 352 if (strncmp (params, "form ", 5) == 0)
370 { 353 {
371 int player_count; 354 int player_count;
372 player *pl;
373 355
374 params += 5; 356 params += 5;
375 if (op->contr->party) 357 if (op->contr->party)
376 oldparty = op->contr->party; 358 oldparty = op->contr->party;
377 else 359 else
400 * 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
401 */ 383 */
402 player_count = 0; 384 player_count = 0;
403 if (oldparty) 385 if (oldparty)
404 { 386 {
405 for (pl = first_player; pl->next != NULL; pl = pl->next) 387 for_all_players (pl)
406 {
407 if (pl->party == oldparty) 388 if (pl->party == oldparty)
408 player_count++; 389 player_count++;
409 } 390
410 if (player_count == 0) 391 if (player_count == 0)
411 remove_party (oldparty); 392 remove_party (oldparty);
412 } 393 }
394
413 return 0; 395 return 0;
414 } /* form */ 396 } /* form */
415 397
416 if (strcmp (params, "leave") == 0) 398 if (strcmp (params, "leave") == 0)
417 { 399 {
425 sprintf (buf, "%s leaves party %s.", &op->name, currentparty); 407 sprintf (buf, "%s leaves party %s.", &op->name, currentparty);
426 send_party_message (op, buf); 408 send_party_message (op, buf);
427 op->contr->party = NULL; 409 op->contr->party = NULL;
428 return 1; 410 return 1;
429 } 411 }
412
430 if (strcmp (params, "who") == 0) 413 if (strcmp (params, "who") == 0)
431 { 414 {
432 player *pl;
433
434 tmpparty = op->contr->party; 415 tmpparty = op->contr->party;
435 if (op->contr->party == NULL) 416 if (op->contr->party == NULL)
436 { 417 {
437 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.");
438 return 1; 419 return 1;
439 } 420 }
440 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);
441 for (pl = first_player; pl != NULL; pl = pl->next) 422 for_all_players (pl)
442 if (pl->ob->contr->party == op->contr->party) 423 if (pl->ob->contr->party == op->contr->party)
443 { 424 {
444 if (settings.set_title == TRUE) 425 if (settings.set_title == TRUE)
445 { 426 {
446 if (pl->ob->contr->own_title[0] != '\0') 427 if (pl->ob->contr->own_title[0] != '\0')
598 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");
599 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>");
600 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");
601 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>");
602 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");
603#ifdef PARTY_KILL_LOG
604 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");
605#endif
606 return 1; 585 return 1;
607} 586}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines