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 | |
28 | |
30 | #ifdef COZY_SERVER |
29 | #ifdef COZY_SERVER |
31 | // used for pet monster logic etc. |
30 | // used for pet monster logic etc. |
32 | int |
31 | int |
… | |
… | |
54 | form_party (object *op, const char *params) |
53 | form_party (object *op, const char *params) |
55 | { |
54 | { |
56 | partylist *newparty; |
55 | partylist *newparty; |
57 | |
56 | |
58 | newparty = (partylist *) malloc (sizeof (partylist)); |
57 | newparty = (partylist *) malloc (sizeof (partylist)); |
59 | newparty->partyname = strdup_local (params); |
58 | newparty->partyname = strdup (params); |
60 | newparty->total_exp = 0; |
59 | newparty->total_exp = 0; |
61 | newparty->kills = 0; |
60 | newparty->kills = 0; |
62 | newparty->passwd[0] = '\0'; |
61 | newparty->passwd[0] = '\0'; |
63 | newparty->next = NULL; |
62 | newparty->next = NULL; |
64 | newparty->partyleader = strdup_local (op->name); |
63 | newparty->partyleader = strdup (op->name); |
65 | 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); |
66 | op->contr->party = newparty; |
65 | op->contr->party = newparty; |
67 | |
66 | |
68 | return newparty; |
67 | return newparty; |
69 | } |
68 | } |
… | |
… | |
72 | remove_party (partylist *target_party) |
71 | remove_party (partylist *target_party) |
73 | { |
72 | { |
74 | partylist *tmpparty; |
73 | partylist *tmpparty; |
75 | partylist *previousparty; |
74 | partylist *previousparty; |
76 | partylist *nextparty; |
75 | partylist *nextparty; |
77 | player *pl; |
|
|
78 | |
76 | |
79 | if (firstparty == NULL) |
77 | if (firstparty == NULL) |
80 | { |
78 | { |
81 | 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); |
82 | return; |
80 | return; |
83 | } |
81 | } |
84 | |
82 | |
85 | for (pl = first_player; pl != NULL; pl = pl->next) |
83 | for_all_players (pl) |
86 | if (pl->party == target_party) |
84 | if (pl->party == target_party) |
87 | pl->party = NULL; |
85 | pl->party = NULL; |
88 | |
86 | |
89 | /* 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 */ |
90 | if (target_party == firstparty) |
88 | if (target_party == firstparty) |
… | |
… | |
140 | /* 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. */ |
141 | void |
139 | void |
142 | obsolete_parties (void) |
140 | obsolete_parties (void) |
143 | { |
141 | { |
144 | int player_count; |
142 | int player_count; |
145 | player *pl; |
|
|
146 | partylist *party; |
143 | partylist *party; |
147 | partylist *next = NULL; |
144 | partylist *next = NULL; |
148 | |
145 | |
149 | if (!firstparty) |
146 | if (!firstparty) |
150 | return; /* we can't obsolete parties if there aren't any */ |
147 | return; /* we can't obsolete parties if there aren't any */ |
151 | for (party = firstparty; party != NULL; party = next) |
148 | for (party = firstparty; party != NULL; party = next) |
152 | { |
149 | { |
153 | next = party->next; |
150 | next = party->next; |
154 | player_count = 0; |
151 | player_count = 0; |
155 | for (pl = first_player; pl != NULL; pl = pl->next) |
152 | for_all_players (pl) |
156 | if (pl->party == party) |
153 | if (pl->party == party) |
157 | player_count++; |
154 | player_count++; |
158 | if (player_count == 0) |
155 | if (player_count == 0) |
159 | remove_party (party); |
156 | remove_party (party); |
160 | } |
157 | } |
161 | } |
158 | } |
162 | |
159 | |
163 | #ifdef PARTY_KILL_LOG |
|
|
164 | void |
160 | void |
165 | add_kill_to_party (partylist *party, char *killer, char *dead, long exp) |
161 | add_kill_to_party (partylist *party, const char *killer, const char *dead, long exp) |
166 | { |
162 | { |
167 | int i, pos; |
163 | int i, pos; |
168 | |
164 | |
169 | if (party == NULL) |
165 | if (party == NULL) |
170 | return; |
166 | return; |
|
|
167 | |
171 | if (party->kills >= PARTY_KILL_LOG) |
168 | if (party->kills >= PARTY_KILL_LOG) |
172 | { |
169 | { |
173 | pos = PARTY_KILL_LOG - 1; |
170 | pos = PARTY_KILL_LOG - 1; |
174 | for (i = 0; i < PARTY_KILL_LOG - 1; i++) |
171 | for (i = 0; i < PARTY_KILL_LOG - 1; i++) |
175 | party->party_kills[i] = party->party_kills[i + 1]; |
172 | party->party_kills[i] = party->party_kills[i + 1]; |
176 | } |
173 | } |
177 | else |
174 | else |
178 | pos = party->kills; |
175 | pos = party->kills; |
|
|
176 | |
179 | party->kills++; |
177 | party->kills++; |
180 | party->total_exp += exp; |
178 | party->total_exp += exp; |
181 | party->party_kills[pos].exp = exp; |
179 | party->party_kills[pos].exp = exp; |
182 | assign (party->party_kills[pos].killer, killer); |
180 | assign (party->party_kills[pos].killer, killer); |
183 | assign (party->party_kills[pos].dead, dead); |
181 | assign (party->party_kills[pos].dead, dead); |
184 | party->party_kills[pos].killer[MAX_NAME] = 0; |
182 | party->party_kills[pos].killer[MAX_NAME] = 0; |
185 | party->party_kills[pos].dead[MAX_NAME] = 0; |
183 | party->party_kills[pos].dead[MAX_NAME] = 0; |
186 | } |
184 | } |
187 | #endif |
|
|
188 | |
185 | |
189 | int |
186 | int |
190 | confirm_party_password (object *op) |
187 | confirm_party_password (object *op) |
191 | { |
188 | { |
192 | partylist *tmppartylist; |
189 | partylist *tmppartylist; |
… | |
… | |
216 | op->contr->party = op->contr->party_to_join; |
213 | op->contr->party = op->contr->party_to_join; |
217 | op->contr->party_to_join = NULL; |
214 | op->contr->party_to_join = NULL; |
218 | 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); |
219 | 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); |
220 | send_party_message (op, buf); |
217 | send_party_message (op, buf); |
221 | op->contr->state = ST_PLAYING; |
218 | op->contr->ns->state = ST_PLAYING; |
222 | return; |
219 | return; |
223 | } |
220 | } |
224 | else |
221 | else |
225 | { |
222 | { |
226 | 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"); |
227 | op->contr->party_to_join = NULL; |
224 | op->contr->party_to_join = NULL; |
228 | op->contr->state = ST_PLAYING; |
225 | op->contr->ns->state = ST_PLAYING; |
229 | return; |
226 | return; |
230 | } |
227 | } |
231 | } |
228 | } |
232 | |
229 | |
233 | void |
230 | void |
234 | send_party_message (object *op, char *msg) |
231 | send_party_message (object *op, char *msg) |
235 | { |
232 | { |
236 | player *pl; |
233 | 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) |
234 | if (pl->ob->contr->party == op->contr->party && pl->ob != op) |
240 | new_draw_info (NDI_WHITE, 0, pl->ob, msg); |
235 | new_draw_info (NDI_WHITE, 0, pl->ob, msg); |
241 | } |
236 | } |
242 | |
237 | |
243 | int |
238 | int |
… | |
… | |
245 | { |
240 | { |
246 | char party_params[MAX_BUF]; |
241 | char party_params[MAX_BUF]; |
247 | |
242 | |
248 | if (!params) |
243 | if (!params) |
249 | return 0; |
244 | return 0; |
|
|
245 | |
250 | strcpy (party_params, "say "); |
246 | strcpy (party_params, "say "); |
251 | strcat (party_params, params); |
247 | strcat (party_params, params); |
252 | command_party (op, party_params); |
248 | command_party (op, party_params); |
253 | return 0; |
249 | return 0; |
254 | } |
250 | } |
255 | |
251 | |
256 | |
|
|
257 | int |
252 | int |
258 | command_party (object *op, char *params) |
253 | command_party (object *op, char *params) |
259 | { |
254 | { |
260 | char buf[MAX_BUF]; |
255 | char buf[MAX_BUF]; |
261 | partylist *tmpparty, *oldparty; /* For iterating over linked list */ |
256 | partylist *tmpparty, *oldparty; /* For iterating over linked list */ |
… | |
… | |
273 | currentparty = op->contr->party->partyname; |
268 | currentparty = op->contr->party->partyname; |
274 | 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); |
275 | } |
270 | } |
276 | return 1; |
271 | return 1; |
277 | } |
272 | } |
|
|
273 | |
278 | if (strcmp (params, "help") == 0) |
274 | if (strcmp (params, "help") == 0) |
279 | { |
275 | { |
280 | 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>"); |
281 | 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>"); |
282 | 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."); |
… | |
… | |
284 | 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"); |
285 | 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>"); |
286 | 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"); |
287 | 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>"); |
288 | 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"); |
289 | #ifdef PARTY_KILL_LOG |
|
|
290 | 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"); |
291 | #endif |
|
|
292 | return 1; |
286 | return 1; |
293 | } |
287 | } |
294 | #ifdef PARTY_KILL_LOG |
288 | |
295 | if (!strncmp (params, "kills", 5)) |
289 | if (!strncmp (params, "kills", 5)) |
296 | { |
290 | { |
297 | int i, max; |
291 | int i, max; |
298 | char chr; |
292 | char chr; |
299 | char buffer[80]; |
293 | char buffer[80]; |
… | |
… | |
347 | new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); |
341 | new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); |
348 | 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); |
349 | new_draw_info (NDI_UNIQUE, 0, op, buffer); |
343 | new_draw_info (NDI_UNIQUE, 0, op, buffer); |
350 | return 1; |
344 | return 1; |
351 | } |
345 | } |
352 | #endif /* PARTY_KILL_LOG */ |
346 | |
353 | if (strncmp (params, "say ", 4) == 0) |
347 | if (strncmp (params, "say ", 4) == 0) |
354 | { |
348 | { |
355 | if (op->contr->party == NULL) |
349 | if (op->contr->party == NULL) |
356 | { |
350 | { |
357 | 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."); |
… | |
… | |
359 | } |
353 | } |
360 | params += 4; |
354 | params += 4; |
361 | currentparty = op->contr->party->partyname; |
355 | currentparty = op->contr->party->partyname; |
362 | 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); |
363 | send_party_message (op, buf); |
357 | send_party_message (op, buf); |
364 | 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); |
365 | return 1; |
359 | return 1; |
366 | } |
360 | } |
367 | |
361 | |
368 | if (strncmp (params, "form ", 5) == 0) |
362 | if (strncmp (params, "form ", 5) == 0) |
369 | { |
363 | { |
370 | int player_count; |
364 | int player_count; |
371 | player *pl; |
|
|
372 | |
365 | |
373 | params += 5; |
366 | params += 5; |
374 | if (op->contr->party) |
367 | if (op->contr->party) |
375 | oldparty = op->contr->party; |
368 | oldparty = op->contr->party; |
376 | else |
369 | else |
… | |
… | |
399 | * 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 |
400 | */ |
393 | */ |
401 | player_count = 0; |
394 | player_count = 0; |
402 | if (oldparty) |
395 | if (oldparty) |
403 | { |
396 | { |
404 | for (pl = first_player; pl->next != NULL; pl = pl->next) |
397 | for_all_players (pl) |
405 | { |
|
|
406 | if (pl->party == oldparty) |
398 | if (pl->party == oldparty) |
407 | player_count++; |
399 | player_count++; |
408 | } |
400 | |
409 | if (player_count == 0) |
401 | if (player_count == 0) |
410 | remove_party (oldparty); |
402 | remove_party (oldparty); |
411 | } |
403 | } |
|
|
404 | |
412 | return 0; |
405 | return 0; |
413 | } /* form */ |
406 | } /* form */ |
414 | |
407 | |
415 | if (strcmp (params, "leave") == 0) |
408 | if (strcmp (params, "leave") == 0) |
416 | { |
409 | { |
… | |
… | |
424 | sprintf (buf, "%s leaves party %s.", &op->name, currentparty); |
417 | sprintf (buf, "%s leaves party %s.", &op->name, currentparty); |
425 | send_party_message (op, buf); |
418 | send_party_message (op, buf); |
426 | op->contr->party = NULL; |
419 | op->contr->party = NULL; |
427 | return 1; |
420 | return 1; |
428 | } |
421 | } |
|
|
422 | |
429 | if (strcmp (params, "who") == 0) |
423 | if (strcmp (params, "who") == 0) |
430 | { |
424 | { |
431 | player *pl; |
|
|
432 | |
|
|
433 | tmpparty = op->contr->party; |
425 | tmpparty = op->contr->party; |
434 | if (op->contr->party == NULL) |
426 | if (op->contr->party == NULL) |
435 | { |
427 | { |
436 | 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."); |
437 | return 1; |
429 | return 1; |
438 | } |
430 | } |
439 | 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); |
440 | for (pl = first_player; pl != NULL; pl = pl->next) |
432 | for_all_players (pl) |
441 | if (pl->ob->contr->party == op->contr->party) |
433 | if (pl->ob->contr->party == op->contr->party) |
442 | { |
434 | { |
443 | if (settings.set_title == TRUE) |
435 | if (settings.set_title == TRUE) |
444 | { |
436 | { |
445 | if (pl->ob->contr->own_title[0] != '\0') |
437 | if (pl->ob->contr->own_title[0] != '\0') |
… | |
… | |
597 | 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"); |
598 | 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>"); |
599 | 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"); |
600 | 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>"); |
601 | 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"); |
602 | #ifdef PARTY_KILL_LOG |
|
|
603 | 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"); |
604 | #endif |
|
|
605 | return 1; |
595 | return 1; |
606 | } |
596 | } |