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.117 by root, Sun Apr 29 21:44:35 2007 UTC vs.
Revision 1.118 by root, Mon Apr 30 04:25:30 2007 UTC

202 202
203 ob->remove (); 203 ob->remove ();
204 ob->map = 0; 204 ob->map = 0;
205 party = 0; 205 party = 0;
206 206
207 // for weird reasons, this is often "ob", keeping a circular reference 207 combat_skill = ranged_skill = 0; //TODO, should be special marker, non-refcounted, not this
208 ranges [range_skill] = 0;
209 208
210 players.erase (this); 209 players.erase (this);
211} 210}
212 211
213// connect the player with a specific client 212// connect the player with a specific client
230 ns->reset_stats (); 229 ns->reset_stats ();
231 230
232 /* make sure he's a player -- needed because of class change. */ 231 /* make sure he's a player -- needed because of class change. */
233 ob->type = PLAYER; // we are paranoid 232 ob->type = PLAYER; // we are paranoid
234 ob->race = ob->arch->clone.race; 233 ob->race = ob->arch->clone.race;
235
236 if (!legal_range (shoottype))
237 shoottype = range_none;
238 234
239 ob->carrying = sum_weight (ob); 235 ob->carrying = sum_weight (ob);
240 link_player_skills (ob); 236 link_player_skills (ob);
241 237
242 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 238 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
325 unapply = unapply_nochoice; 321 unapply = unapply_nochoice;
326 322
327 savebed_map = first_map_path; /* Init. respawn position */ 323 savebed_map = first_map_path; /* Init. respawn position */
328 324
329 gen_sp_armour = 10; 325 gen_sp_armour = 10;
330 shoottype = range_none;
331 bowtype = bow_normal; 326 bowtype = bow_normal;
332 petmode = pet_normal; 327 petmode = pet_normal;
333 listening = 10; 328 listening = 10;
334 usekeys = containers; 329 usekeys = containers;
335 peaceful = 1; /* default peaceful */ 330 peaceful = 1; /* default peaceful */
1549 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1544 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1550 return 0; 1545 return 0;
1551 } 1546 }
1552 1547
1553 if (op->type == PLAYER) 1548 if (op->type == PLAYER)
1554 bow = op->contr->ranges[range_bow]; 1549 bow = op->contr->ranged_ob;
1555 else 1550 else
1556 { 1551 {
1557 for (bow = op->inv; bow; bow = bow->below) 1552 for (bow = op->inv; bow; bow = bow->below)
1558 /* Don't check for applied - monsters don't apply bows - in that way, they 1553 /* Don't check for applied - monsters don't apply bows - in that way, they
1559 * don't need to switch back and forth between bows and weapons. 1554 * don't need to switch back and forth between bows and weapons.
1564 if (!bow) 1559 if (!bow)
1565 { 1560 {
1566 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1561 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1567 return 0; 1562 return 0;
1568 } 1563 }
1564
1565 // optimisation: move object to top so we will find it quickly again
1566 if (bow->below)
1567 {
1568 bow->remove ();
1569 op->insert (bow);
1570 }
1571
1569 } 1572 }
1570 1573
1571 if (!bow->race || !bow->skill) 1574 if (!bow->race || !bow->skill)
1572 { 1575 {
1573 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1576 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1705{ 1708{
1706 int ret = 0, wcmod = 0; 1709 int ret = 0, wcmod = 0;
1707 1710
1708 if (op->contr->bowtype == bow_bestarrow) 1711 if (op->contr->bowtype == bow_bestarrow)
1709 { 1712 {
1710 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranges[range_bow]->race, dir), dir, 0, op->x, op->y); 1713 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y);
1711 } 1714 }
1712 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1715 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1713 { 1716 {
1714 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1717 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1))
1715 wcmod = -1; 1718 wcmod = -1;
1742 * Broken apart from 'fire' to keep it more readable. 1745 * Broken apart from 'fire' to keep it more readable.
1743 */ 1746 */
1744void 1747void
1745fire_misc_object (object *op, int dir) 1748fire_misc_object (object *op, int dir)
1746{ 1749{
1747 object *item; 1750 object *item = op->contr->ranged_ob;
1748 1751
1749 if (!op->contr->ranges[range_misc]) 1752 if (!item)
1750 { 1753 {
1751 new_draw_info (NDI_UNIQUE, 0, op, "You have range item readied."); 1754 new_draw_info (NDI_UNIQUE, 0, op, "You have range item readied.");
1752 return; 1755 return;
1753 } 1756 }
1754 1757
1755 item = op->contr->ranges[range_misc];
1756 if (!item->inv) 1758 if (!item->inv)
1757 { 1759 {
1758 LOG (llevError, "Object %s lacks a spell\n", &item->name); 1760 LOG (llevError, "Object %s lacks a spell\n", &item->name);
1759 return; 1761 return;
1760 } 1762 }
1763
1761 if (item->type == WAND) 1764 if (item->type == WAND)
1762 { 1765 {
1763 if (item->stats.food <= 0) 1766 if (item->stats.food <= 0)
1764 { 1767 {
1765 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1768 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0);
1814 1817
1815 /* check for loss of invisiblity/hide */ 1818 /* check for loss of invisiblity/hide */
1816 if (action_makes_visible (op)) 1819 if (action_makes_visible (op))
1817 make_visible (op); 1820 make_visible (op);
1818 1821
1819 switch (op->contr->shoottype) 1822 player *pl = op->contr;
1820 { 1823
1821 case range_none: 1824 object *skill = pl->ranged_skill;
1825 object *rob = pl->ranged_ob;
1826
1827 if (!skill)
1822 return; 1828 return;
1823 1829
1824 case range_bow: 1830 if (pl->golem)
1831 control_golem (op->contr->golem, dir);
1832 else if (skill->type == SKILL)
1833 {
1834 if (skill_flags [skill->subtype] & SF_NEED_BOW)
1825 player_fire_bow (op, dir); 1835 player_fire_bow (op, dir);
1826 return; 1836 else if (rob && rob->type == SPELL) /* Casting spells */
1827
1828 case range_magic: /* Casting spells */
1829 spellcost = (cast_spell (op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : 0)); 1837 spellcost = cast_spell (op, op, dir, rob, pl->spellparam[0] ? pl->spellparam : 0);
1830 return; 1838 else
1831 1839 LOG (llevError, "skill %s ready but do not know what to do with its ob: %s\n",
1832 case range_misc: 1840 &skill->name, rob ? &rob->name : "(null)");
1833 fire_misc_object (op, dir); 1841 }
1834 return; 1842 else if (skill == op)
1835 1843 {
1836 case range_golem: /* Control summoned monsters from scrolls */ 1844 if (!rob)
1837 control_golem (op->contr->ranges[range_golem], dir);
1838 return;
1839
1840 case range_skill:
1841 if (!op->chosen_skill)
1842 { 1845 {
1843 if (op->type == PLAYER) 1846 LOG (llevError, "self-skill ready but no ranged ob: %s\n", skill->debug_desc ());
1844 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use.");
1845
1846 return; 1847 return;
1847 } 1848 }
1848 1849
1849 do_skill (op, op, op->chosen_skill, dir, NULL); 1850 if (rob->type == BUILDER)
1850 return;
1851 case range_builder:
1852 apply_map_builder (op, dir); 1851 apply_map_builder (op, dir);
1853 return; 1852 else if (rob->type == SKILL || rob->type == SKILL_TOOL)
1854 default: 1853 do_skill (op, op, rob, dir, NULL);
1855 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); 1854 else
1856 return; 1855 fire_misc_object (op, dir); //TODO: should become use_magic_item skill usage
1857 } 1856 }
1858} 1857}
1859 1858
1860/* find_key 1859/* find_key
1861 * We try to find a key for the door as passed. If we find a key 1860 * We try to find a key for the door as passed. If we find a key
2451 gen_grace = op->stats.maxgrace; 2450 gen_grace = op->stats.maxgrace;
2452 rate_grace -= rate_grace / 2 * op->contr->gen_grace; 2451 rate_grace -= rate_grace / 2 * op->contr->gen_grace;
2453 } 2452 }
2454 2453
2455 /* Regenerate Spell Points */ 2454 /* Regenerate Spell Points */
2456 if (!op->contr->ranges[range_golem] && --op->last_sp < 0) 2455 if (!op->contr->golem && --op->last_sp < 0)
2457 { 2456 {
2458 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);
2459 if (op->stats.sp < op->stats.maxsp) 2458 if (op->stats.sp < op->stats.maxsp)
2460 { 2459 {
2461 op->stats.sp++; 2460 op->stats.sp++;
3496 * not readied. 3495 * not readied.
3497 */ 3496 */
3498void 3497void
3499player_unready_range_ob (player *pl, object *ob) 3498player_unready_range_ob (player *pl, object *ob)
3500{ 3499{
3501 for (rangetype i = (rangetype) 0; i < range_size; i = (rangetype) ((int) i + 1)) 3500 if (pl->combat_ob == ob)
3502 if (pl->ranges[i] == ob)
3503 { 3501 {
3504 pl->ranges[i] = 0; 3502 pl->combat_skill = 0;
3505 if (pl->shoottype == i) 3503 pl->combat_ob = 0;
3506 pl->shoottype = range_none;
3507 } 3504 }
3505
3506 if (pl->ranged_ob == ob)
3507 {
3508 pl->ranged_skill = 0;
3509 pl->ranged_ob = 0;
3510 }
3508} 3511}
3509 3512
3510sint8 3513sint8
3511player::visibility_at (maptile *map, int x, int y) const 3514player::visibility_at (maptile *map, int x, int y) const
3512{ 3515{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines