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. |
33 | int |
31 | int |
… | |
… | |
55 | form_party (object *op, const char *params) |
53 | form_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 | } |
… | |
… | |
81 | { |
79 | { |
82 | LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); |
80 | LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); |
83 | return; |
81 | return; |
84 | } |
82 | } |
85 | |
83 | |
86 | for (pl = first_player; pl != NULL; pl = pl->next) |
84 | for_all_players (pl) |
87 | if (pl->party == target_party) |
85 | if (pl->party == target_party) |
88 | pl->party = NULL; |
86 | pl->party = NULL; |
89 | |
87 | |
90 | /* special case-ism for parties at the beginning and end of the list */ |
88 | /* special case-ism for parties at the beginning and end of the list */ |
91 | if (target_party == firstparty) |
89 | if (target_party == firstparty) |
… | |
… | |
151 | return; /* we can't obsolete parties if there aren't any */ |
149 | return; /* we can't obsolete parties if there aren't any */ |
152 | for (party = firstparty; party != NULL; party = next) |
150 | for (party = firstparty; party != NULL; party = next) |
153 | { |
151 | { |
154 | next = party->next; |
152 | next = party->next; |
155 | player_count = 0; |
153 | player_count = 0; |
156 | for (pl = first_player; pl != NULL; pl = pl->next) |
154 | for_all_players (pl) |
157 | if (pl->party == party) |
155 | if (pl->party == party) |
158 | player_count++; |
156 | player_count++; |
159 | if (player_count == 0) |
157 | if (player_count == 0) |
160 | remove_party (party); |
158 | remove_party (party); |
161 | } |
159 | } |
162 | } |
160 | } |
163 | |
161 | |
164 | #ifdef PARTY_KILL_LOG |
|
|
165 | void |
162 | void |
166 | add_kill_to_party (partylist *party, char *killer, char *dead, long exp) |
163 | add_kill_to_party (partylist *party, char *killer, char *dead, long exp) |
167 | { |
164 | { |
168 | int i, pos; |
165 | int i, pos; |
169 | |
166 | |
170 | if (party == NULL) |
167 | if (party == NULL) |
171 | return; |
168 | return; |
|
|
169 | |
172 | if (party->kills >= PARTY_KILL_LOG) |
170 | if (party->kills >= PARTY_KILL_LOG) |
173 | { |
171 | { |
174 | pos = PARTY_KILL_LOG - 1; |
172 | pos = PARTY_KILL_LOG - 1; |
175 | for (i = 0; i < PARTY_KILL_LOG - 1; i++) |
173 | for (i = 0; i < PARTY_KILL_LOG - 1; i++) |
176 | party->party_kills[i] = party->party_kills[i + 1]; |
174 | party->party_kills[i] = party->party_kills[i + 1]; |
177 | } |
175 | } |
178 | else |
176 | else |
179 | pos = party->kills; |
177 | pos = party->kills; |
|
|
178 | |
180 | party->kills++; |
179 | party->kills++; |
181 | party->total_exp += exp; |
180 | party->total_exp += exp; |
182 | party->party_kills[pos].exp = exp; |
181 | party->party_kills[pos].exp = exp; |
183 | strncpy (party->party_kills[pos].killer, killer, MAX_NAME); |
182 | assign (party->party_kills[pos].killer, killer); |
184 | strncpy (party->party_kills[pos].dead, dead, MAX_NAME); |
183 | assign (party->party_kills[pos].dead, dead); |
185 | party->party_kills[pos].killer[MAX_NAME] = 0; |
184 | party->party_kills[pos].killer[MAX_NAME] = 0; |
186 | party->party_kills[pos].dead[MAX_NAME] = 0; |
185 | party->party_kills[pos].dead[MAX_NAME] = 0; |
187 | } |
186 | } |
188 | #endif |
|
|
189 | |
187 | |
190 | int |
188 | int |
191 | confirm_party_password (object *op) |
189 | confirm_party_password (object *op) |
192 | { |
190 | { |
193 | partylist *tmppartylist; |
191 | partylist *tmppartylist; |
… | |
… | |
217 | op->contr->party = op->contr->party_to_join; |
215 | op->contr->party = op->contr->party_to_join; |
218 | op->contr->party_to_join = NULL; |
216 | op->contr->party_to_join = NULL; |
219 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s\n", joined_party->partyname); |
217 | 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); |
218 | snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, joined_party->partyname); |
221 | send_party_message (op, buf); |
219 | send_party_message (op, buf); |
222 | op->contr->state = ST_PLAYING; |
220 | op->contr->ns->state = ST_PLAYING; |
223 | return; |
221 | return; |
224 | } |
222 | } |
225 | else |
223 | else |
226 | { |
224 | { |
227 | new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password"); |
225 | new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password"); |
228 | op->contr->party_to_join = NULL; |
226 | op->contr->party_to_join = NULL; |
229 | op->contr->state = ST_PLAYING; |
227 | op->contr->ns->state = ST_PLAYING; |
230 | return; |
228 | return; |
231 | } |
229 | } |
232 | } |
230 | } |
233 | |
231 | |
234 | void |
232 | void |
235 | send_party_message (object *op, char *msg) |
233 | send_party_message (object *op, char *msg) |
236 | { |
234 | { |
237 | player *pl; |
235 | player *pl; |
238 | |
236 | |
239 | for (pl = first_player; pl != NULL; pl = pl->next) |
237 | for_all_players (pl) |
240 | if (pl->ob->contr->party == op->contr->party && pl->ob != op) |
238 | if (pl->ob->contr->party == op->contr->party && pl->ob != op) |
241 | new_draw_info (NDI_WHITE, 0, pl->ob, msg); |
239 | new_draw_info (NDI_WHITE, 0, pl->ob, msg); |
242 | } |
240 | } |
243 | |
241 | |
244 | int |
242 | int |
… | |
… | |
246 | { |
244 | { |
247 | char party_params[MAX_BUF]; |
245 | char party_params[MAX_BUF]; |
248 | |
246 | |
249 | if (!params) |
247 | if (!params) |
250 | return 0; |
248 | return 0; |
|
|
249 | |
251 | strcpy (party_params, "say "); |
250 | strcpy (party_params, "say "); |
252 | strcat (party_params, params); |
251 | strcat (party_params, params); |
253 | command_party (op, party_params); |
252 | command_party (op, party_params); |
254 | return 0; |
253 | return 0; |
255 | } |
254 | } |
256 | |
255 | |
257 | |
|
|
258 | int |
256 | int |
259 | command_party (object *op, char *params) |
257 | command_party (object *op, char *params) |
260 | { |
258 | { |
261 | char buf[MAX_BUF]; |
259 | char buf[MAX_BUF]; |
262 | partylist *tmpparty, *oldparty; /* For iterating over linked list */ |
260 | partylist *tmpparty, *oldparty; /* For iterating over linked list */ |
… | |
… | |
274 | currentparty = op->contr->party->partyname; |
272 | currentparty = op->contr->party->partyname; |
275 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are a member of party %s.", currentparty); |
273 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are a member of party %s.", currentparty); |
276 | } |
274 | } |
277 | return 1; |
275 | return 1; |
278 | } |
276 | } |
|
|
277 | |
279 | if (strcmp (params, "help") == 0) |
278 | if (strcmp (params, "help") == 0) |
280 | { |
279 | { |
281 | new_draw_info (NDI_UNIQUE, 0, op, "To form a party type: party form <partyname>"); |
280 | 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>"); |
281 | 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."); |
282 | 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"); |
284 | 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>"); |
285 | 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"); |
286 | 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>"); |
287 | 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"); |
288 | 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"); |
289 | new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills"); |
292 | #endif |
|
|
293 | return 1; |
290 | return 1; |
294 | } |
291 | } |
295 | #ifdef PARTY_KILL_LOG |
292 | |
296 | if (!strncmp (params, "kills", 5)) |
293 | if (!strncmp (params, "kills", 5)) |
297 | { |
294 | { |
298 | int i, max; |
295 | int i, max; |
299 | char chr; |
296 | char chr; |
300 | char buffer[80]; |
297 | char buffer[80]; |
… | |
… | |
348 | new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); |
345 | new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); |
349 | sprintf (buffer, "Totals: %d kills, %.1f%c exp", tmpparty->kills, exp, chr); |
346 | sprintf (buffer, "Totals: %d kills, %.1f%c exp", tmpparty->kills, exp, chr); |
350 | new_draw_info (NDI_UNIQUE, 0, op, buffer); |
347 | new_draw_info (NDI_UNIQUE, 0, op, buffer); |
351 | return 1; |
348 | return 1; |
352 | } |
349 | } |
353 | #endif /* PARTY_KILL_LOG */ |
350 | |
354 | if (strncmp (params, "say ", 4) == 0) |
351 | if (strncmp (params, "say ", 4) == 0) |
355 | { |
352 | { |
356 | if (op->contr->party == NULL) |
353 | if (op->contr->party == NULL) |
357 | { |
354 | { |
358 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
355 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
… | |
… | |
360 | } |
357 | } |
361 | params += 4; |
358 | params += 4; |
362 | currentparty = op->contr->party->partyname; |
359 | currentparty = op->contr->party->partyname; |
363 | snprintf (buf, MAX_BUF - 1, "[%s] %s says: %s", currentparty, &op->name, params); |
360 | snprintf (buf, MAX_BUF - 1, "[%s] %s says: %s", currentparty, &op->name, params); |
364 | send_party_message (op, buf); |
361 | send_party_message (op, buf); |
365 | new_draw_info_format (NDI_WHITE, 0, op, "[%s] You say: %s", currentparty, params); |
362 | new_draw_info_format (NDI_LT_GREEN | NDI_UNIQUE, 0, op, "[%s] You say: %s", currentparty, params); |
366 | return 1; |
363 | return 1; |
367 | } |
364 | } |
368 | |
365 | |
369 | if (strncmp (params, "form ", 5) == 0) |
366 | if (strncmp (params, "form ", 5) == 0) |
370 | { |
367 | { |
… | |
… | |
400 | * it, so check if there are any other members and if not, delete the party |
397 | * it, so check if there are any other members and if not, delete the party |
401 | */ |
398 | */ |
402 | player_count = 0; |
399 | player_count = 0; |
403 | if (oldparty) |
400 | if (oldparty) |
404 | { |
401 | { |
405 | for (pl = first_player; pl->next != NULL; pl = pl->next) |
402 | for_all_players (pl) |
406 | { |
|
|
407 | if (pl->party == oldparty) |
403 | if (pl->party == oldparty) |
408 | player_count++; |
404 | player_count++; |
409 | } |
405 | |
410 | if (player_count == 0) |
406 | if (player_count == 0) |
411 | remove_party (oldparty); |
407 | remove_party (oldparty); |
412 | } |
408 | } |
|
|
409 | |
413 | return 0; |
410 | return 0; |
414 | } /* form */ |
411 | } /* form */ |
415 | |
412 | |
416 | if (strcmp (params, "leave") == 0) |
413 | if (strcmp (params, "leave") == 0) |
417 | { |
414 | { |
… | |
… | |
425 | sprintf (buf, "%s leaves party %s.", &op->name, currentparty); |
422 | sprintf (buf, "%s leaves party %s.", &op->name, currentparty); |
426 | send_party_message (op, buf); |
423 | send_party_message (op, buf); |
427 | op->contr->party = NULL; |
424 | op->contr->party = NULL; |
428 | return 1; |
425 | return 1; |
429 | } |
426 | } |
|
|
427 | |
430 | if (strcmp (params, "who") == 0) |
428 | if (strcmp (params, "who") == 0) |
431 | { |
429 | { |
432 | player *pl; |
430 | player *pl; |
433 | |
431 | |
434 | tmpparty = op->contr->party; |
432 | tmpparty = op->contr->party; |
… | |
… | |
436 | { |
434 | { |
437 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
435 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
438 | return 1; |
436 | return 1; |
439 | } |
437 | } |
440 | new_draw_info_format (NDI_UNIQUE, 0, op, "Members of party: %s.", op->contr->party->partyname); |
438 | 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) |
439 | for_all_players (pl) |
442 | if (pl->ob->contr->party == op->contr->party) |
440 | if (pl->ob->contr->party == op->contr->party) |
443 | { |
441 | { |
444 | if (settings.set_title == TRUE) |
442 | if (settings.set_title == TRUE) |
445 | { |
443 | { |
446 | if (pl->ob->contr->own_title[0] != '\0') |
444 | if (pl->ob->contr->own_title[0] != '\0') |
… | |
… | |
598 | new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave"); |
596 | 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>"); |
597 | 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"); |
598 | 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>"); |
599 | 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"); |
600 | 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"); |
601 | new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills"); |
605 | #endif |
|
|
606 | return 1; |
602 | return 1; |
607 | } |
603 | } |