… | |
… | |
158 | |
158 | |
159 | /* This loads the first map an puts the player on it. */ |
159 | /* This loads the first map an puts the player on it. */ |
160 | static void |
160 | static void |
161 | set_first_map (object *op) |
161 | set_first_map (object *op) |
162 | { |
162 | { |
163 | strcpy (op->contr->maplevel, first_map_path); |
163 | op->contr->maplevel = first_map_path; |
164 | op->x = -1; |
164 | op->x = -1; |
165 | op->y = -1; |
165 | op->y = -1; |
|
|
166 | } |
|
|
167 | |
|
|
168 | void |
|
|
169 | player::enter_map () |
|
|
170 | { |
|
|
171 | object *tmp = object::create (); |
|
|
172 | |
|
|
173 | EXIT_PATH (tmp) = maplevel; |
|
|
174 | EXIT_X (tmp) = ob->x; |
|
|
175 | EXIT_Y (tmp) = ob->y; |
166 | enter_exit (op, 0); |
176 | ob->enter_exit (tmp); |
|
|
177 | |
|
|
178 | tmp->destroy (); |
167 | } |
179 | } |
168 | |
180 | |
169 | // connect the player with a specific client |
181 | // connect the player with a specific client |
170 | // also changed, rationalises, and fixes some incorrect settings |
182 | // also changed, rationalises, and fixes some incorrect settings |
171 | void |
183 | void |
… | |
… | |
191 | |
203 | |
192 | ob->carrying = sum_weight (ob); |
204 | ob->carrying = sum_weight (ob); |
193 | link_player_skills (ob); |
205 | link_player_skills (ob); |
194 | |
206 | |
195 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
207 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
196 | ob->set_speed (ob->speed); |
|
|
197 | |
208 | |
198 | assign (title, ob->arch->clone.name); |
209 | assign (title, ob->arch->clone.name); |
199 | |
210 | |
200 | /* can_use_shield is a new flag. However, the can_use.. seems to largely come |
211 | /* can_use_shield is a new flag. However, the can_use.. seems to largely come |
201 | * from the class, and not race. I don't see any way to get the class information |
212 | * from the class, and not race. I don't see any way to get the class information |
… | |
… | |
238 | ns->floorbox_update (); |
249 | ns->floorbox_update (); |
239 | |
250 | |
240 | esrv_send_inventory (ob, ob); |
251 | esrv_send_inventory (ob, ob); |
241 | esrv_add_spells (this, 0); |
252 | esrv_add_spells (this, 0); |
242 | |
253 | |
243 | enter_exit (ob, 0); |
254 | ob->activate_recursive (); |
|
|
255 | enter_map (); |
244 | |
256 | |
245 | send_rules (ob); |
257 | send_rules (ob); |
246 | send_news (ob); |
258 | send_news (ob); |
247 | display_motd (ob); |
259 | display_motd (ob); |
|
|
260 | |
|
|
261 | INVOKE_PLAYER (CONNECT, this); |
248 | INVOKE_PLAYER (LOGIN, this); |
262 | INVOKE_PLAYER (LOGIN, this); |
249 | } |
263 | } |
250 | |
264 | |
251 | void |
265 | void |
252 | player::disconnect () |
266 | player::disconnect () |
253 | { |
267 | { |
|
|
268 | if (ob) |
|
|
269 | ob->deactivate_recursive (); |
|
|
270 | |
254 | //TODO: don't be so harsh and destroy :) |
271 | //TODO: don't be so harsh and destroy :) |
255 | if (ns) |
272 | if (ns) |
256 | { |
273 | { |
257 | if (enable_save) |
274 | if (enable_save) |
|
|
275 | { |
258 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
276 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
|
|
277 | save (true); |
|
|
278 | } |
|
|
279 | |
|
|
280 | INVOKE_PLAYER (DISCONNECT, this); |
259 | |
281 | |
260 | client *ns = this->ns; |
282 | client *ns = this->ns; |
261 | ns->send_packet ("goodbye"); |
283 | ns->send_packet ("goodbye"); |
262 | ns->flush (); |
284 | ns->flush (); |
263 | ns->pl = 0; |
285 | ns->pl = 0; |
… | |
… | |
280 | ob->speed = 1.0; |
302 | ob->speed = 1.0; |
281 | ob->direction = 5; /* So player faces south */ |
303 | ob->direction = 5; /* So player faces south */ |
282 | ob->stats.wc = 2; |
304 | ob->stats.wc = 2; |
283 | ob->run_away = 25; /* Then we panick... */ |
305 | ob->run_away = 25; /* Then we panick... */ |
284 | |
306 | |
285 | set_first_map (ob); |
|
|
286 | |
|
|
287 | ob->roll_stats (); |
307 | ob->roll_stats (); |
288 | } |
308 | } |
289 | |
309 | |
290 | player::player () |
310 | player::player () |
291 | { |
311 | { |
292 | /* There are some elements we want initialized to non zero value - |
312 | /* There are some elements we want initialised to non zero value - |
293 | * we deal with that below this point. |
313 | * we deal with that below this point. |
294 | */ |
314 | */ |
295 | outputs_sync = 16; /* Every 2 seconds */ |
315 | outputs_sync = 16; /* Every 2 seconds */ |
296 | outputs_count = 8; /* Keeps present behaviour */ |
316 | outputs_count = 8; /* Keeps present behaviour */ |
297 | unapply = unapply_nochoice; |
317 | unapply = unapply_nochoice; |
298 | |
318 | |
299 | assign (savebed_map, first_map_path); /* Init. respawn position */ |
319 | savebed_map = first_map_path; /* Init. respawn position */ |
300 | |
320 | |
301 | gen_sp_armour = 10; |
321 | gen_sp_armour = 10; |
302 | last_speed = -1; |
322 | last_speed = -1; |
303 | shoottype = range_none; |
323 | shoottype = range_none; |
304 | bowtype = bow_normal; |
324 | bowtype = bow_normal; |
… | |
… | |
375 | player::create () |
395 | player::create () |
376 | { |
396 | { |
377 | player *pl = new player; |
397 | player *pl = new player; |
378 | |
398 | |
379 | pl->set_object (arch_to_object (get_player_archetype (0))); |
399 | pl->set_object (arch_to_object (get_player_archetype (0))); |
|
|
400 | set_first_map (pl->ob); |
380 | |
401 | |
381 | return pl; |
402 | return pl; |
382 | } |
403 | } |
383 | |
404 | |
384 | /* |
405 | /* |
… | |
… | |
850 | |
871 | |
851 | contr->orig_stats = stats; |
872 | contr->orig_stats = stats; |
852 | } |
873 | } |
853 | } |
874 | } |
854 | |
875 | |
|
|
876 | static void |
|
|
877 | start_info (object *op) |
|
|
878 | { |
|
|
879 | char buf[MAX_BUF]; |
|
|
880 | |
|
|
881 | sprintf (buf, "Welcome to Crossfire v%s!", VERSION); |
|
|
882 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
883 | //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help"); |
|
|
884 | //new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
885 | } |
|
|
886 | |
855 | /* This function takes the key that is passed, and does the |
887 | /* This function takes the key that is passed, and does the |
856 | * appropriate action with it (change race, or other things). |
888 | * appropriate action with it (change race, or other things). |
857 | * The function name is for historical reasons - now we have |
889 | * The function name is for historical reasons - now we have |
858 | * separate race and class; this actually changes the RACE, |
890 | * separate race and class; this actually changes the RACE, |
859 | * not the class. |
891 | * not the class. |
… | |
… | |
904 | if (*first_map_ext_path) |
936 | if (*first_map_ext_path) |
905 | { |
937 | { |
906 | object *tmp; |
938 | object *tmp; |
907 | char mapname[MAX_BUF]; |
939 | char mapname[MAX_BUF]; |
908 | |
940 | |
909 | snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); |
941 | snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &op->arch->name); |
910 | tmp = object::create (); |
942 | tmp = object::create (); |
911 | EXIT_PATH (tmp) = mapname; |
943 | EXIT_PATH (tmp) = mapname; |
912 | EXIT_X (tmp) = op->x; |
944 | EXIT_X (tmp) = op->x; |
913 | EXIT_Y (tmp) = op->y; |
945 | EXIT_Y (tmp) = op->y; |
914 | enter_exit (op, tmp); /* we don't really care if it succeeded; |
946 | op->enter_exit (tmp); /* we don't really care if it succeeded; |
915 | * if the map isn't there, then stay on the |
947 | * if the map isn't there, then stay on the |
916 | * default initial map */ |
948 | * default initial map */ |
917 | tmp->destroy (); |
949 | tmp->destroy (); |
918 | } |
950 | } |
919 | else |
951 | else |
… | |
… | |
976 | INVOKE_PLAYER (QUIT, op->contr); |
1008 | INVOKE_PLAYER (QUIT, op->contr); |
977 | |
1009 | |
978 | op->contr->enable_save = false; |
1010 | op->contr->enable_save = false; |
979 | |
1011 | |
980 | terminate_all_pets (op); |
1012 | terminate_all_pets (op); |
981 | leave_map (op); |
1013 | op->remove (); |
982 | op->direction = 0; |
1014 | op->direction = 0; |
983 | new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name); |
1015 | new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name); |
984 | |
1016 | |
985 | strcpy (op->contr->killer, "quit"); |
1017 | strcpy (op->contr->killer, "quit"); |
986 | check_score (op); |
1018 | check_score (op); |
987 | op->contr->party = 0; |
1019 | op->contr->party = 0; |
988 | op->contr->own_title[0] = '\0'; |
1020 | op->contr->own_title[0] = '\0'; |
989 | |
|
|
990 | object_ptr ob = op; |
|
|
991 | |
|
|
992 | /* We need to hunt for any per player unique maps in memory and |
|
|
993 | * get rid of them. The trailing slash in the path is intentional, |
|
|
994 | * so that players named 'Ab' won't match against players 'Abe' pathname |
|
|
995 | */ |
|
|
996 | char buf[MAX_BUF]; |
|
|
997 | sprintf (buf, "%s/%s/%s/", settings.localdir, settings.playerdir, &op->name); |
|
|
998 | |
|
|
999 | for_all_maps (mp) |
|
|
1000 | if (!strncmp (mp->path, buf, strlen (buf))) |
|
|
1001 | delete_map (mp); |
|
|
1002 | |
|
|
1003 | delete_character (ob->name, 1); |
|
|
1004 | ob->contr->destroy (); |
1021 | op->contr->destroy (); |
1005 | |
1022 | |
1006 | return 1; |
1023 | return 1; |
1007 | } |
1024 | } |
1008 | |
1025 | |
1009 | void |
1026 | void |
… | |
… | |
1753 | } |
1770 | } |
1754 | else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) |
1771 | else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) |
1755 | { |
1772 | { |
1756 | if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) |
1773 | if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) |
1757 | wcmod = -1; |
1774 | wcmod = -1; |
|
|
1775 | |
1758 | ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); |
1776 | ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); |
1759 | } |
1777 | } |
1760 | else if (op->contr->bowtype == bow_threewide) |
1778 | else if (op->contr->bowtype == bow_threewide) |
1761 | { |
1779 | { |
1762 | ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); |
1780 | ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); |
… | |
… | |
2334 | |
2352 | |
2335 | /* call this here - we also will call this in do_ericserver, but |
2353 | /* call this here - we also will call this in do_ericserver, but |
2336 | * the players time has been increased when doericserver has been |
2354 | * the players time has been increased when doericserver has been |
2337 | * called, so we recheck it here. |
2355 | * called, so we recheck it here. |
2338 | */ |
2356 | */ |
2339 | //TODO: better than handling 8 commands, use some more intelligent rate-limiting |
2357 | op->contr->ns->handle_command (); |
2340 | for (int rep = 8; --rep && op->contr->ns->handle_command (); ) |
|
|
2341 | ; |
|
|
2342 | |
2358 | |
2343 | if (op->speed_left < 0) |
2359 | if (op->speed_left < 0) |
2344 | return 0; |
2360 | return 0; |
2345 | |
2361 | |
2346 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2362 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
… | |
… | |
3308 | if (pl->type != PLAYER) |
3324 | if (pl->type != PLAYER) |
3309 | { |
3325 | { |
3310 | LOG (llevError, "player_can_view() called for non-player object\n"); |
3326 | LOG (llevError, "player_can_view() called for non-player object\n"); |
3311 | return -1; |
3327 | return -1; |
3312 | } |
3328 | } |
|
|
3329 | |
3313 | if (!pl || !op) |
3330 | if (!pl || !op) |
3314 | return 0; |
3331 | return 0; |
3315 | |
3332 | |
3316 | if (op->head) |
|
|
3317 | { |
|
|
3318 | op = op->head; |
3333 | op = op->head_ (); |
3319 | } |
3334 | |
3320 | get_rangevector (pl, op, &rv, 0x1); |
3335 | get_rangevector (pl, op, &rv, 0x1); |
3321 | |
3336 | |
3322 | /* starting with the 'head' part, lets loop |
3337 | /* starting with the 'head' part, lets loop |
3323 | * through the object and find if it has any |
3338 | * through the object and find if it has any |
3324 | * part that is in the los array but isnt on |
3339 | * part that is in the los array but isnt on |
… | |
… | |
3454 | if (trlist == NULL || who->type != PLAYER) |
3469 | if (trlist == NULL || who->type != PLAYER) |
3455 | return; |
3470 | return; |
3456 | |
3471 | |
3457 | for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); |
3472 | for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); |
3458 | |
3473 | |
3459 | if (tr == NULL || tr->item == NULL) |
3474 | if (!tr || !tr->item) |
3460 | { |
3475 | { |
3461 | /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ |
3476 | /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ |
3462 | return; |
3477 | return; |
3463 | } |
3478 | } |
3464 | |
3479 | |