1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | |
3 | * |
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
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 author can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The author can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <pwd.h> |
26 | #include <pwd.h> |
27 | #include <sproto.h> |
27 | #include <sproto.h> |
28 | #include <sounds.h> |
28 | #include <sounds.h> |
… | |
… | |
32 | #include <skills.h> |
32 | #include <skills.h> |
33 | |
33 | |
34 | #include <algorithm> |
34 | #include <algorithm> |
35 | #include <functional> |
35 | #include <functional> |
36 | |
36 | |
37 | player * |
37 | playervec players; |
38 | find_player (const char *plname) |
|
|
39 | { |
|
|
40 | for_all_players (pl) |
|
|
41 | if (pl->ob && !strcmp (query_name (pl->ob), plname)) |
|
|
42 | return pl; |
|
|
43 | |
|
|
44 | return 0; |
|
|
45 | } |
|
|
46 | |
38 | |
47 | void |
39 | void |
48 | display_motd (const object *op) |
40 | display_motd (const object *op) |
49 | { |
41 | { |
50 | char buf[MAX_BUF]; |
42 | char buf[MAX_BUF]; |
… | |
… | |
133 | |
125 | |
134 | if (*buf == '%') |
126 | if (*buf == '%') |
135 | { /* send one news */ |
127 | { /* send one news */ |
136 | if (size > 0) |
128 | if (size > 0) |
137 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ |
129 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ |
|
|
130 | |
138 | strcpy (subject, buf + 1); |
131 | strcpy (subject, buf + 1); |
139 | strip_endline (subject); |
132 | strip_endline (subject); |
140 | size = 0; |
133 | size = 0; |
141 | news[0] = '\0'; |
134 | news[0] = '\0'; |
142 | } |
135 | } |
… | |
… | |
177 | ob->enter_exit (tmp); |
170 | ob->enter_exit (tmp); |
178 | |
171 | |
179 | tmp->destroy (); |
172 | tmp->destroy (); |
180 | } |
173 | } |
181 | |
174 | |
|
|
175 | void |
|
|
176 | player::activate () |
|
|
177 | { |
|
|
178 | if (active) |
|
|
179 | return; |
|
|
180 | |
|
|
181 | players.insert (this); |
|
|
182 | ob->remove (); |
|
|
183 | ob->map = 0; |
|
|
184 | ob->activate_recursive (); |
|
|
185 | enter_map (); |
|
|
186 | } |
|
|
187 | |
|
|
188 | void |
|
|
189 | player::deactivate () |
|
|
190 | { |
|
|
191 | if (!active) |
|
|
192 | return; |
|
|
193 | |
|
|
194 | terminate_all_pets (ob); |
|
|
195 | ob->deactivate_recursive (); |
|
|
196 | ob->remove (); |
|
|
197 | ob->map = 0; |
|
|
198 | |
|
|
199 | players.erase (this); |
|
|
200 | } |
|
|
201 | |
182 | // connect the player with a specific client |
202 | // connect the player with a specific client |
183 | // also changed, rationalises, and fixes some incorrect settings |
203 | // also changed, rationalises, and fixes some incorrect settings |
184 | void |
204 | void |
185 | player::connect (client *ns) |
205 | player::connect (client *ns) |
186 | { |
206 | { |
187 | this->ns = ns; |
207 | this->ns = ns; |
188 | ns->pl = this; |
208 | ns->pl = this; |
189 | |
|
|
190 | next = first_player; |
|
|
191 | first_player = this; |
|
|
192 | |
209 | |
193 | ns->update_look = 0; |
210 | ns->update_look = 0; |
194 | ns->look_position = 0; |
211 | ns->look_position = 0; |
195 | |
212 | |
196 | clear_los (ob); |
213 | clear_los (ob); |
… | |
… | |
250 | ns->floorbox_update (); |
267 | ns->floorbox_update (); |
251 | |
268 | |
252 | esrv_send_inventory (ob, ob); |
269 | esrv_send_inventory (ob, ob); |
253 | esrv_add_spells (this, 0); |
270 | esrv_add_spells (this, 0); |
254 | |
271 | |
255 | ob->activate_recursive (); |
272 | activate (); |
256 | enter_map (); |
|
|
257 | |
273 | |
258 | send_rules (ob); |
274 | send_rules (ob); |
259 | send_news (ob); |
275 | send_news (ob); |
260 | display_motd (ob); |
276 | display_motd (ob); |
261 | |
277 | |
… | |
… | |
264 | } |
280 | } |
265 | |
281 | |
266 | void |
282 | void |
267 | player::disconnect () |
283 | player::disconnect () |
268 | { |
284 | { |
269 | if (ob) |
|
|
270 | ob->deactivate_recursive (); |
|
|
271 | |
|
|
272 | //TODO: don't be so harsh and destroy :) |
285 | //TODO: don't be so harsh and destroy :) |
273 | if (ns) |
286 | if (ns) |
274 | { |
287 | { |
275 | if (enable_save) |
288 | if (active) |
276 | { |
|
|
277 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
289 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
278 | save (true); |
|
|
279 | } |
|
|
280 | |
290 | |
281 | INVOKE_PLAYER (DISCONNECT, this); |
291 | INVOKE_PLAYER (DISCONNECT, this); |
282 | |
292 | |
283 | client *ns = this->ns; |
|
|
284 | ns->send_packet ("goodbye"); |
|
|
285 | ns->flush (); |
|
|
286 | ns->pl = 0; |
293 | ns->pl = 0; |
287 | this->ns = 0; |
294 | this->ns = 0; |
288 | |
|
|
289 | ns->destroy (); |
|
|
290 | destroy (); |
|
|
291 | } |
295 | } |
|
|
296 | |
|
|
297 | deactivate (); |
292 | } |
298 | } |
293 | |
299 | |
294 | // the need for this function can be explained |
300 | // the need for this function can be explained |
295 | // by load_object not returning the object |
301 | // by load_object not returning the object |
296 | void |
302 | void |
… | |
… | |
348 | void |
354 | void |
349 | player::do_destroy () |
355 | player::do_destroy () |
350 | { |
356 | { |
351 | disconnect (); |
357 | disconnect (); |
352 | |
358 | |
353 | save (false); |
|
|
354 | enable_save = false; |
|
|
355 | |
|
|
356 | attachable::do_destroy (); |
359 | attachable::do_destroy (); |
357 | |
|
|
358 | terminate_all_pets (ob); |
|
|
359 | |
|
|
360 | if (first_player != this) |
|
|
361 | { |
|
|
362 | player *prev = first_player; |
|
|
363 | |
|
|
364 | while (prev && prev->next && prev->next != this) |
|
|
365 | prev = prev->next; |
|
|
366 | |
|
|
367 | if (prev->next != this) |
|
|
368 | { |
|
|
369 | LOG (llevError, "Free_player: Can't find previous player.\n"); |
|
|
370 | abort (); |
|
|
371 | } |
|
|
372 | |
|
|
373 | prev->next = next; |
|
|
374 | } |
|
|
375 | else |
|
|
376 | first_player = next; |
|
|
377 | |
360 | |
378 | if (ob) |
361 | if (ob) |
379 | { |
362 | { |
380 | ob->destroy_inv (false); |
363 | ob->destroy_inv (false); |
381 | ob->destroy (); |
364 | ob->destroy (); |
… | |
… | |
993 | |
976 | |
994 | send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
977 | send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
995 | return 0; |
978 | return 0; |
996 | } |
979 | } |
997 | |
980 | |
998 | int |
|
|
999 | key_confirm_quit (object *op, char key) |
|
|
1000 | { |
|
|
1001 | if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') |
|
|
1002 | { |
|
|
1003 | op->contr->ns->state = ST_PLAYING; |
|
|
1004 | new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play."); |
|
|
1005 | return 1; |
|
|
1006 | } |
|
|
1007 | |
|
|
1008 | INVOKE_PLAYER (LOGOUT, op->contr); |
|
|
1009 | INVOKE_PLAYER (QUIT, op->contr); |
|
|
1010 | |
|
|
1011 | op->contr->enable_save = false; |
|
|
1012 | delete_character (op->name); |
|
|
1013 | |
|
|
1014 | terminate_all_pets (op); |
|
|
1015 | op->remove (); |
|
|
1016 | op->direction = 0; |
|
|
1017 | new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name); |
|
|
1018 | |
|
|
1019 | strcpy (op->contr->killer, "quit"); |
|
|
1020 | check_score (op); |
|
|
1021 | op->contr->party = 0; |
|
|
1022 | op->contr->own_title[0] = '\0'; |
|
|
1023 | op->contr->destroy (); |
|
|
1024 | |
|
|
1025 | return 1; |
|
|
1026 | } |
|
|
1027 | |
|
|
1028 | void |
981 | void |
1029 | flee_player (object *op) |
982 | flee_player (object *op) |
1030 | { |
983 | { |
1031 | int dir, diff; |
984 | int dir, diff; |
1032 | rv_vector rv; |
985 | rv_vector rv; |
… | |
… | |
2775 | |
2728 | |
2776 | command_kill_pets (op, 0); |
2729 | command_kill_pets (op, 0); |
2777 | |
2730 | |
2778 | if (op->stats.food < 0) |
2731 | if (op->stats.food < 0) |
2779 | { |
2732 | { |
2780 | if (op->contr->explore) |
|
|
2781 | { |
|
|
2782 | new_draw_info (NDI_UNIQUE, 0, op, "You would have starved, but you are"); |
|
|
2783 | new_draw_info (NDI_UNIQUE, 0, op, "in explore mode, so..."); |
|
|
2784 | op->stats.food = 999; |
|
|
2785 | return; |
|
|
2786 | } |
|
|
2787 | sprintf (buf, "%s starved to death.", &op->name); |
2733 | sprintf (buf, "%s starved to death.", &op->name); |
2788 | strcpy (op->contr->killer, "starvation"); |
2734 | strcpy (op->contr->killer, "starvation"); |
2789 | } |
2735 | } |
2790 | else |
2736 | else |
2791 | { |
|
|
2792 | if (op->contr->explore) |
|
|
2793 | { |
|
|
2794 | new_draw_info (NDI_UNIQUE, 0, op, "You would have died, but you are"); |
|
|
2795 | new_draw_info (NDI_UNIQUE, 0, op, "in explore mode, so..."); |
|
|
2796 | op->stats.hp = op->stats.maxhp; |
|
|
2797 | return; |
|
|
2798 | } |
|
|
2799 | sprintf (buf, "%s died.", &op->name); |
2737 | sprintf (buf, "%s died.", &op->name); |
2800 | } |
|
|
2801 | |
2738 | |
2802 | play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); |
2739 | play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); |
2803 | |
2740 | |
2804 | /* save the map location for corpse, gravestone */ |
2741 | /* save the map location for corpse, gravestone */ |
2805 | x = op->x; |
2742 | x = op->x; |
… | |
… | |
2998 | /* */ |
2935 | /* */ |
2999 | /****************************************/ |
2936 | /****************************************/ |
3000 | |
2937 | |
3001 | enter_player_savebed (op); |
2938 | enter_player_savebed (op); |
3002 | |
2939 | |
3003 | /* Save the player before inserting the force to reduce |
|
|
3004 | * chance of abuse. |
|
|
3005 | */ |
|
|
3006 | op->contr->braced = 0; |
2940 | op->contr->braced = 0; |
3007 | op->contr->save (); |
|
|
3008 | |
2941 | |
3009 | /* it is possible that the player has blown something up |
2942 | /* it is possible that the player has blown something up |
3010 | * at his savebed location, and that can have long lasting |
2943 | * at his savebed location, and that can have long lasting |
3011 | * spell effects. So first see if there is a spell effect |
2944 | * spell effects. So first see if there is a spell effect |
3012 | * on the space that might harm the player. |
2945 | * on the space that might harm the player. |