ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/player.C
(Generate patch)

Comparing deliantra/server/server/player.C (file contents):
Revision 1.111 by root, Mon Apr 23 11:43:22 2007 UTC vs.
Revision 1.116 by root, Sun Apr 29 03:44:36 2007 UTC

291 291
292 INVOKE_PLAYER (DISCONNECT, this); 292 INVOKE_PLAYER (DISCONNECT, this);
293 293
294 ns->reset_stats (); 294 ns->reset_stats ();
295 ns->pl = 0; 295 ns->pl = 0;
296 this->ns = 0; 296 ns = 0;
297 } 297 }
298 298
299 if (ob) 299 if (ob)
300 ob->close_container (); //TODO: client-specific 300 ob->close_container (); //TODO: client-specific
301 301
318player::player () 318player::player ()
319{ 319{
320 /* There are some elements we want initialised to non zero value - 320 /* There are some elements we want initialised to non zero value -
321 * we deal with that below this point. 321 * we deal with that below this point.
322 */ 322 */
323 outputs_sync = 6; /* Every 2 seconds */ 323 outputs_sync = 4;
324 outputs_count = 10; /* Keeps present behaviour */ 324 outputs_count = 4;
325 unapply = unapply_nochoice; 325 unapply = unapply_nochoice;
326 326
327 savebed_map = first_map_path; /* Init. respawn position */ 327 savebed_map = first_map_path; /* Init. respawn position */
328 328
329 gen_sp_armour = 10; 329 gen_sp_armour = 10;
868 * appropriate action with it (change race, or other things). 868 * appropriate action with it (change race, or other things).
869 * The function name is for historical reasons - now we have 869 * The function name is for historical reasons - now we have
870 * separate race and class; this actually changes the RACE, 870 * separate race and class; this actually changes the RACE,
871 * not the class. 871 * not the class.
872 */ 872 */
873int 873void
874key_change_class (object *op, char key) 874player::chargen_race_done ()
875{ 875{
876 int tmp_loop;
877
878 if (key == 'd' || key == 'D')
879 {
880 char buf[MAX_BUF];
881
882 /* this must before then initial items are given */ 876 /* this must before then initial items are given */
883 esrv_new_player (op->contr, op->weight + op->carrying); 877 esrv_new_player (ob->contr, ob->weight + ob->carrying);
884 878
885 treasurelist *tl = treasurelist::find ("starting_wealth"); 879 treasurelist *tl = treasurelist::find ("starting_wealth");
886 if (tl) 880 if (tl)
887 create_treasure (tl, op, 0, 0, 0); 881 create_treasure (tl, ob, 0, 0, 0);
888 882
889 INVOKE_PLAYER (BIRTH, op->contr); 883 INVOKE_PLAYER (BIRTH, ob->contr);
890 INVOKE_PLAYER (LOGIN, op->contr); 884 INVOKE_PLAYER (LOGIN, ob->contr);
891 885
892 op->contr->ns->state = ST_PLAYING; 886 ob->contr->ns->state = ST_PLAYING;
893 887
894 if (op->msg) 888 if (ob->msg)
895 op->msg = NULL; 889 ob->msg = 0;
896 890
897 /* We create this now because some of the unique maps will need it 891 /* We create this now because some of the unique maps will need it
898 * to save here. 892 * to save here.
899 */ 893 */
894 {
895 char buf[MAX_BUF];
900 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &op->name); 896 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
901 make_path_to_file (buf); 897 make_path_to_file (buf);
898 }
902 899
903 start_info (op); 900 start_info (ob);
904 CLEAR_FLAG (op, FLAG_WIZ); 901 CLEAR_FLAG (ob, FLAG_WIZ);
905 give_initial_items (op, op->randomitems); 902 give_initial_items (ob, ob->randomitems);
906 link_player_skills (op); 903 link_player_skills (ob);
907 esrv_send_inventory (op, op); 904 esrv_send_inventory (ob, ob);
908 op->update_stats (); 905 ob->update_stats ();
909 906
910 /* This moves the player to a different start map, if there 907 /* This moves the player to a different start map, if there
911 * is one for this race 908 * is one for this race
912 */ 909 */
913 if (*first_map_ext_path) 910 if (*first_map_ext_path)
914 { 911 {
915 object *tmp; 912 object *tmp;
916 char mapname[MAX_BUF]; 913 char mapname[MAX_BUF];
917 914
918 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &op->arch->name); 915 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->name);
919 tmp = object::create (); 916 tmp = object::create ();
920 EXIT_PATH (tmp) = mapname; 917 EXIT_PATH (tmp) = mapname;
921 EXIT_X (tmp) = op->x; 918 EXIT_X (tmp) = ob->x;
922 EXIT_Y (tmp) = op->y; 919 EXIT_Y (tmp) = ob->y;
923 op->enter_exit (tmp); /* we don't really care if it succeeded; 920 ob->enter_exit (tmp); /* we don't really care if it succeeded;
924 * if the map isn't there, then stay on the 921 * if the map isn't there, then stay on the
925 * default initial map */ 922 * default initial map */
926 tmp->destroy (); 923 tmp->destroy ();
927 } 924 }
928 else 925 else
929 LOG (llevDebug, "first_map_ext_path not set\n"); 926 LOG (llevDebug, "first_map_ext_path not set\n");
927}
930 928
931 return 0; 929void
932 } 930player::chargen_race_next ()
933 931{
934 /* Following actually changes the race - this is the default command 932 /* Following actually changes the race - this is the default command
935 * if we don't match with one of the options above. 933 * if we don't match with one of the options above.
936 */ 934 */
937 935
938 tmp_loop = 0; 936 do
939 while (!tmp_loop)
940 { 937 {
941 shstr name = op->name; 938 shstr name = ob->name;
942 int x = op->x, y = op->y; 939 int x = ob->x, y = ob->y;
943 940
944 op->remove_statbonus (); 941 ob->remove_statbonus ();
945 op->remove (); 942 ob->remove ();
946 op->arch = get_player_archetype (op->arch); 943 ob->arch = get_player_archetype (ob->arch);
947 op->arch->clone.copy_to (op); 944 ob->arch->clone.copy_to (ob);
948 op->instantiate (); 945 ob->instantiate ();
949 op->stats = op->contr->orig_stats; 946 ob->stats = ob->contr->orig_stats;
950 op->name = op->name_pl = name; 947 ob->name = ob->name_pl = name;
951 op->x = x; 948 ob->x = x;
952 op->y = y; 949 ob->y = y;
953 SET_ANIMATION (op, 2); /* So player faces south */ 950 SET_ANIMATION (ob, 2); /* So player faces south */
954 insert_ob_in_map (op, op->map, op, 0); 951 insert_ob_in_map (ob, ob->map, ob, 0);
955 assign (op->contr->title, op->arch->clone.name); 952 assign (ob->contr->title, ob->arch->clone.name);
956 op->add_statbonus (); 953 ob->add_statbonus ();
957 tmp_loop = allowed_class (op);
958 } 954 }
955 while (!allowed_class (ob));
959 956
960 update_object (op, UP_OBJ_FACE); 957 update_object (ob, UP_OBJ_FACE);
961 esrv_update_item (UPD_FACE, op, op); 958 esrv_update_item (UPD_FACE, ob, ob);
962 op->update_stats (); 959 ob->update_stats ();
963 op->stats.hp = op->stats.maxhp; 960 ob->stats.hp = ob->stats.maxhp;
964 op->stats.sp = op->stats.maxsp; 961 ob->stats.sp = ob->stats.maxsp;
965 op->stats.grace = 0; 962 ob->stats.grace = 0;
966
967 if (op->msg)
968 new_draw_info (NDI_BLUE, 0, op, op->msg);
969
970 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
971 return 0;
972} 963}
973 964
974void 965void
975flee_player (object *op) 966flee_player (object *op)
976{ 967{
1599 if (op->type == PLAYER) 1590 if (op->type == PLAYER)
1600 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1591 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1601 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */ 1592 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
1602 else 1593 else
1603 CLEAR_FLAG (op, FLAG_READY_BOW); 1594 CLEAR_FLAG (op, FLAG_READY_BOW);
1595
1604 return 0; 1596 return 0;
1605 } 1597 }
1606 } 1598 }
1607 1599
1608 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); 1600 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy);
1639 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; 1631 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed;
1640 op->update_stats (); 1632 op->update_stats ();
1641 } 1633 }
1642 1634
1643 SET_ANIMATION (arrow, arrow->direction); 1635 SET_ANIMATION (arrow, arrow->direction);
1636
1644 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1637 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1645 arrow->stats.hp = arrow->stats.dam; 1638 arrow->stats.hp = arrow->stats.dam;
1646 arrow->stats.grace = arrow->attacktype; 1639 arrow->stats.grace = arrow->attacktype;
1640
1647 if (arrow->slaying != NULL) 1641 if (arrow->slaying)
1648 arrow->spellarg = strdup (arrow->slaying); 1642 arrow->spellarg = strdup (arrow->slaying);
1649 1643
1650 /* Note that this was different for monsters - they got their level 1644 arrow->stats.dam += op->stats.dam + arrow->magic;
1651 * added to the damage. I think the strength bonus is more proper.
1652 */
1653
1654 arrow->stats.dam += (QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? 0 : dam_bonus[op->stats.Str]) + bow->stats.dam + bow->magic + arrow->magic;
1655 1645
1656 /* update the speed */ 1646 /* update the speed */
1657 arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? 1647 arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ?
1658 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0; 1648 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0;
1659 1649
1660 arrow->set_speed (max (arrow->speed, 1.0)); 1650 arrow->set_speed (max (arrow->speed, 1.0));
1661 arrow->speed_left = 0; 1651 arrow->speed_left = 0;
1662 1652
1653 arrow->stats.wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1654
1663 if (op->type == PLAYER) 1655 if (op->type == PLAYER)
1664 { 1656 {
1665 arrow->stats.wc = 20 - bow->magic - arrow->magic -
1666 (op->chosen_skill ? op->chosen_skill->level : op->level) -
1667 dex_bonus[op->stats.Dex] - thaco_bonus[op->stats.Str] - arrow->stats.wc - bow->stats.wc + wc_mod;
1668
1669 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1657 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1658 arrow->stats.wc -= dex_bonus[op->stats.Dex];
1659
1660 if (!arrow->slaying)
1661 arrow->slaying = op->slaying;
1670 } 1662 }
1671 else 1663 else
1672 { 1664 {
1673 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod;
1674 arrow->level = op->level; 1665 arrow->level = op->level;
1675 } 1666 arrow->stats.wc -= bow->magic;
1676 1667
1677 if (arrow->attacktype == AT_PHYSICAL) 1668 if (!arrow->slaying)
1669 arrow->slaying = bow->slaying;
1670 }
1671
1672 arrow->stats.wc -= arrow->level;
1673
1678 arrow->attacktype |= bow->attacktype; 1674 arrow->attacktype |= bow->attacktype;
1679
1680 if (bow->slaying)
1681 arrow->slaying = bow->slaying;
1682 1675
1683 arrow->move_type = MOVE_FLY_LOW; 1676 arrow->move_type = MOVE_FLY_LOW;
1684 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1677 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1685 1678
1686 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1679 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1839 case range_misc: 1832 case range_misc:
1840 fire_misc_object (op, dir); 1833 fire_misc_object (op, dir);
1841 return; 1834 return;
1842 1835
1843 case range_golem: /* Control summoned monsters from scrolls */ 1836 case range_golem: /* Control summoned monsters from scrolls */
1844 if (QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
1845 {
1846 op->contr->ranges[range_golem] = 0;
1847 op->contr->shoottype = range_none;
1848 }
1849 else
1850 control_golem (op->contr->ranges[range_golem], dir); 1837 control_golem (op->contr->ranges[range_golem], dir);
1851 return; 1838 return;
1852 1839
1853 case range_skill: 1840 case range_skill:
1854 if (!op->chosen_skill) 1841 if (!op->chosen_skill)
1855 { 1842 {
1856 if (op->type == PLAYER) 1843 if (op->type == PLAYER)
1857 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use."); 1844 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use.");
1845
1858 return; 1846 return;
1859 } 1847 }
1860 1848
1861 do_skill (op, op, op->chosen_skill, dir, NULL); 1849 do_skill (op, op, op->chosen_skill, dir, NULL);
1862 return; 1850 return;
2270 op->speed_left--; 2258 op->speed_left--;
2271 return 0; 2259 return 0;
2272 } 2260 }
2273 } 2261 }
2274 2262
2275 /* I've been seeing crashes where the golem has been destroyed, but
2276 * the player object still points to the defunct golem. The code that
2277 * destroys the golem looks correct, and it doesn't always happen, so
2278 * put this in a a workaround to clean up the golem pointer.
2279 */
2280 if (op->contr->ranges[range_golem] && QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2281 op->contr->ranges[range_golem] = 0;
2282
2283 /* call this here - we also will call this in do_ericserver, but 2263 /* call this here - we also will call this in do_ericserver, but
2284 * the players time has been increased when doericserver has been 2264 * the players time has been increased when doericserver has been
2285 * called, so we recheck it here. 2265 * called, so we recheck it here.
2286 */ 2266 */
2287 if (op->contr->ns->handle_command ()) 2267 if (op->contr->ns->handle_command ())
2441 make_visible (op); 2421 make_visible (op);
2442 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out."); 2422 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out.");
2443 } 2423 }
2444 } 2424 }
2445 2425
2446 if (op->contr->outputs_sync)
2447 for (i = 0; i < NUM_OUTPUT_BUFS; i++)
2448 if (op->contr->outputs[i].buf && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks)
2449 flush_output_element (op, &op->contr->outputs[i]);
2450
2451 if (op->contr->ns->state == ST_PLAYING) 2426 if (op->contr->ns->state == ST_PLAYING)
2452 { 2427 {
2453 /* these next three if clauses make it possible to SLOW DOWN 2428 /* these next three if clauses make it possible to SLOW DOWN
2454 hp/grace/spellpoint regeneration. */ 2429 hp/grace/spellpoint regeneration. */
2455 if (op->contr->gen_hp >= 0) 2430 if (op->contr->gen_hp >= 0)
2475 gen_grace = op->stats.maxgrace; 2450 gen_grace = op->stats.maxgrace;
2476 rate_grace -= rate_grace / 2 * op->contr->gen_grace; 2451 rate_grace -= rate_grace / 2 * op->contr->gen_grace;
2477 } 2452 }
2478 2453
2479 /* Regenerate Spell Points */ 2454 /* Regenerate Spell Points */
2480 if (op->contr->ranges[range_golem] == NULL && --op->last_sp < 0) 2455 if (!op->contr->ranges[range_golem] && --op->last_sp < 0)
2481 { 2456 {
2482 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour); 2457 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2483 if (op->stats.sp < op->stats.maxsp) 2458 if (op->stats.sp < op->stats.maxsp)
2484 { 2459 {
2485 op->stats.sp++; 2460 op->stats.sp++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines