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

Comparing deliantra/server/server/attack.C (file contents):
Revision 1.87 by root, Mon Jul 14 18:36:43 2008 UTC vs.
Revision 1.105 by root, Thu Jan 1 11:41:17 2009 UTC

79 int i, roll, saves = 0, attacks = 0, number; 79 int i, roll, saves = 0, attacks = 0, number;
80 materialtype_t *mt; 80 materialtype_t *mt;
81 81
82 if (!op->materialname) 82 if (!op->materialname)
83 { 83 {
84 for (mt = materialt; mt && mt->next; mt = mt->next) 84 for (mt = materialt; mt; mt = mt->next)
85 if (op->materials & mt->material) 85 if (op->materials & mt->material)
86 break; 86 break;
87 } 87 }
88 else 88 else
89 mt = name_to_material (op->materialname); 89 mt = name_to_material (op->materialname);
148 object *env = op->env; 148 object *env = op->env;
149 int x = op->x, y = op->y; 149 int x = op->x, y = op->y;
150 maptile *m = op->map; 150 maptile *m = op->map;
151 151
152 op = stop_item (op); 152 op = stop_item (op);
153 if (op == NULL) 153 if (!op)
154 return; 154 return;
155 155
156 /* Hacked the following so that type LIGHTER will work. 156 /* Hacked the following so that type LIGHTER will work.
157 * Also, objects which are potential "lights" that are hit by 157 * Also, objects which are potential "lights" that are hit by
158 * flame/elect attacks will be set to glow. "lights" are any 158 * flame/elect attacks will be set to glow. "lights" are any
192 fix_stopped_item (op, m, originator); 192 fix_stopped_item (op, m, originator);
193 } 193 }
194 else 194 else
195 { 195 {
196 // drop everything to the ground, if possible 196 // drop everything to the ground, if possible
197 while (op->inv)
198 op->inv->insert_at (originator); 197 op->insert_at (originator);
199
200 op->destroy (); 198 op->drop_and_destroy ();
201 } 199 }
202 200
203 if (type & (AT_FIRE | AT_ELECTRICITY)) 201 if (type & (AT_FIRE | AT_ELECTRICITY))
204 if (env) 202 if (env)
205 { 203 {
212 210
213 return; 211 return;
214 } 212 }
215 213
216 /* The value of 50 is arbitrary. */ 214 /* The value of 50 is arbitrary. */
217 if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && (RANDOM () & 2)) 215 if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && rndm (2))
218 { 216 {
219 archetype *at = archetype::find (shstr_icecube); 217 archetype *at = archetype::find (shstr_icecube);
220 218
221 if (at == NULL) 219 if (at == NULL)
222 return; 220 return;
782 * for help. */ 780 * for help. */
783 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) 781 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int))
784 npc_call_help (op); 782 npc_call_help (op);
785 783
786 /* if you were hidden and hit by a creature, you are discovered */ 784 /* if you were hidden and hit by a creature, you are discovered */
787 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE)) 785 if (op->flag [FLAG_HIDDEN] && hitter->flag [FLAG_ALIVE])
788 { 786 {
789 make_visible (op); 787 make_visible (op);
790 788
791 if (op->type == PLAYER) 789 if (op->type == PLAYER)
792 new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. " "You are no longer hidden!"); 790 new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. " "You are no longer hidden!");
893 /* Disassemble missile */ 891 /* Disassemble missile */
894 if (op->inv) 892 if (op->inv)
895 { 893 {
896 container = op; 894 container = op;
897 hitter = op->inv; 895 hitter = op->inv;
898 hitter->remove ();
899 insert_ob_in_map (hitter, container->map, hitter, INS_NO_MERGE | INS_NO_WALK_ON); 896 hitter->insert_at (container, hitter, INS_NO_MERGE | INS_NO_WALK_ON);
900 /* Note that we now have an empty THROWN_OBJ on the map. Code that 897 /* Note that we now have an empty THROWN_OBJ on the map. Code that
901 * might be called until this THROWN_OBJ is either reassembled or 898 * might be called until this THROWN_OBJ is either reassembled or
902 * removed at the end of this function must be able to deal with empty 899 * removed at the end of this function must be able to deal with empty
903 * THROWN_OBJs. */ 900 * THROWN_OBJs. */
904 } 901 }
918 * other places as well!) 915 * other places as well!)
919 */ 916 */
920 if (hitter->destroyed () || hitter->env != NULL) 917 if (hitter->destroyed () || hitter->env != NULL)
921 { 918 {
922 if (container) 919 if (container)
923 {
924 container->remove ();
925 container->destroy (); 920 container->destroy ();
926 }
927 921
928 return 0; 922 return 0;
929 } 923 }
930 924
931 /* Missile hit victim */ 925 /* Missile hit victim */
955 * can fly over but not otherwise move over. What is the correct 949 * can fly over but not otherwise move over. What is the correct
956 * way to handle those otherwise? 950 * way to handle those otherwise?
957 */ 951 */
958 if (victim->x != hitter->x || victim->y != hitter->y) 952 if (victim->x != hitter->x || victim->y != hitter->y)
959 { 953 {
954 if (victim->destroyed ())
955 hitter->destroy ();
956 else
957 {
960 hitter->remove (); 958 hitter->remove ();
961 hitter->x = victim->x; 959 hitter->x = victim->x;
962 hitter->y = victim->y; 960 hitter->y = victim->y;
963 insert_ob_in_map (hitter, victim->map, hitter, 0); 961 insert_ob_in_map (hitter, victim->map, hitter, 0);
962 }
964 } 963 }
965 else 964 else
966 /* Else leave arrow where it is */ 965 /* Else leave arrow where it is */
967 merge_ob (hitter, NULL); 966 merge_ob (hitter, NULL);
968 967
1069 if (attacknum == ATNR_INTERNAL) 1068 if (attacknum == ATNR_INTERNAL)
1070 return dam; 1069 return dam;
1071 1070
1072 if (hitter->slaying) 1071 if (hitter->slaying)
1073 { 1072 {
1074 if ((op->race && strstr (hitter->slaying, op->race)) 1073 if ((op->race && hitter->slaying.contains (op->race))
1075 || (op->arch && op->arch->archname && strstr (op->arch->archname, hitter->slaying))) 1074 || (op->arch && op->arch->archname && op->arch->archname.contains (hitter->slaying)))
1076 { 1075 {
1077 doesnt_slay = 0; 1076 doesnt_slay = 0;
1078 dam *= 3; 1077 dam *= 3;
1079 } 1078 }
1080 } 1079 }
1282 object *god = find_god (determine_god (owner)); 1281 object *god = find_god (determine_god (owner));
1283 int div = 1; 1282 int div = 1;
1284 1283
1285 /* if undead are not an enemy of your god, you turn them 1284 /* if undead are not an enemy of your god, you turn them
1286 * at half strength */ 1285 * at half strength */
1287 if (!god || !god->slaying || strstr (god->slaying, shstr_undead) == NULL) 1286 if (!god || !god->slaying || !god->slaying.contains (shstr_undead))
1288 div = 2; 1287 div = 2;
1289 1288
1290 /* Give a bonus if you resist turn undead */ 1289 /* Give a bonus if you resist turn undead */
1291 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100))) 1290 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100)))
1292 scare_creature (op, owner); 1291 scare_creature (op, owner);
1383 */ 1382 */
1384int 1383int
1385kill_object (object *op, int dam, object *hitter, int type) 1384kill_object (object *op, int dam, object *hitter, int type)
1386{ 1385{
1387 char buf[MAX_BUF]; 1386 char buf[MAX_BUF];
1388 const char *skill; 1387 shstr skill;
1389 int maxdam = 0; 1388 int maxdam = 0;
1390 int battleg = 0; /* true if op standing on battleground */ 1389 int battleg = 0; /* true if op standing on battleground */
1391 int pk = 0; /* true if op and what controls hitter are both players */ 1390 int pk = 0; /* true if op and what controls hitter are both players */
1392 object *owner = 0; 1391 object *owner = 0;
1393 object *skop = 0; 1392 object *skop = 0;
1414 return maxdam; 1413 return maxdam;
1415 } 1414 }
1416 1415
1417 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) 1416 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER)
1418 { 1417 {
1419 op->destroy (); 1418 op->drop_and_destroy ();
1420 return maxdam; 1419 return maxdam;
1421 } 1420 }
1422 1421
1423 /* Now lets start dealing with experience we get for killing something */ 1422 /* Now lets start dealing with experience we get for killing something */
1424 1423
1425 owner = hitter->owner; 1424 owner = hitter->outer_owner ();
1426 if (!owner) 1425 if (!owner)
1427 owner = hitter; 1426 owner = hitter;
1428 1427
1429 /* is the victim (op) standing on battleground? */ 1428 /* is the victim (op) standing on battleground? */
1430 if (op_on_battleground (op, NULL, NULL)) 1429 if (op_on_battleground (op, NULL, NULL))
1482 1481
1483 /* This code below deals with finding the appropriate skill 1482 /* This code below deals with finding the appropriate skill
1484 * to credit exp to. This is a bit problematic - we should 1483 * to credit exp to. This is a bit problematic - we should
1485 * probably never really have to look at current_weapon->skill 1484 * probably never really have to look at current_weapon->skill
1486 */ 1485 */
1487 skill = 0;
1488
1489 if (hitter->skill && hitter->type != PLAYER) 1486 if (hitter->skill && hitter->type != PLAYER)
1490 skill = hitter->skill; 1487 skill = hitter->skill;
1491 else if (owner->chosen_skill) 1488 else if (owner->chosen_skill)
1492 { 1489 {
1493 skop = owner->chosen_skill; 1490 skop = owner->chosen_skill;
1494 skill = skop->skill; 1491 skill = skop->skill;
1495 } 1492 }
1496 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON)) 1493 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon)
1497 skill = owner->current_weapon->skill; 1494 skill = owner->current_weapon->skill;
1498 else 1495 else
1496 {
1499 LOG (llevError, "kill_object - unable to find skill that killed monster\n"); 1497 LOG (llevError, "BUG: kill_object - unable to find skill that killed monster\n"
1498 "op: %s\n" "hitter: %s\n" "owner: %s\n",
1499 owner->debug_desc (), hitter->debug_desc (), op->debug_desc ());
1500 skill = 0;
1501 }
1500 1502
1501 /* We have the skill we want to credit to - now find the object this goes 1503 /* We have the skill we want to credit to - now find the object this goes
1502 * to. Make sure skop is an actual skill, and not a skill tool! 1504 * to. Make sure skop is an actual skill, and not a skill tool!
1503 */ 1505 */
1504 if ((!skop || skop->type != SKILL) && skill) 1506 skop = owner->contr->find_skill (skill);
1505 {
1506 int i;
1507
1508 for (i = 0; i < NUM_SKILLS; i++)
1509 if (owner->contr->last_skill_ob[i] && !strcmp (owner->contr->last_skill_ob[i]->skill, skill))
1510 {
1511 skop = owner->contr->last_skill_ob[i];
1512 break;
1513 }
1514 }
1515 } /* Was it a player that hit somethign */ 1507 } /* Was it a player that hit somethign */
1516 else 1508 else
1517 skill = 0; 1509 skill = 0;
1518 1510
1519 /* Pet (or spell) killed something. */
1520 if (owner != hitter)
1521 sprintf (buf, "%s killed %s with %s%s%s.", &owner->name,
1522 query_name (op), query_name (hitter), battleg ? " (duel)" : "", pk ? " (pk)" : "");
1523 else
1524 sprintf (buf, "%s killed %s%s%s%s.", &hitter->name, &op->name,
1525 (QUERY_FLAG (hitter, FLAG_MONSTER)) || hitter->type == PLAYER ?
1526 " in hand to hand combat" : "", battleg ? " (duel)" : "", pk ? " (pk)" : "");
1527
1528 /* These may have been set in the player code section above */ 1511 /* These may have been set in the player code section above */
1529 if (!skop) 1512 if (!skop)
1530 skop = hitter->chosen_skill; 1513 skop = hitter->chosen_skill;
1531 1514
1532 if (!skill && skop) 1515 if (!skill && skop)
1533 skill = skop->skill; 1516 skill = skop->skill;
1534
1535 new_draw_info (NDI_ALL, op->type == PLAYER ? 1 : 10, NULL, buf);
1536 1517
1537 /* If you didn't kill yourself, and your not the wizard */ 1518 /* If you didn't kill yourself, and your not the wizard */
1538 if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) 1519 if (owner != op && !QUERY_FLAG (op, FLAG_WIZ))
1539 { 1520 {
1540 int exp; 1521 int exp;
1612 1593
1613 if (owner1 && owner1->type == PLAYER) 1594 if (owner1 && owner1->type == PLAYER)
1614 { 1595 {
1615 owner1->contr->play_sound (sound_find ("pet_is_killed")); 1596 owner1->contr->play_sound (sound_find ("pet_is_killed"));
1616 /* Maybe we should include the owner that killed this, maybe not */ 1597 /* Maybe we should include the owner that killed this, maybe not */
1617 new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, is killed by %s.", &op->name, &hitter->name); 1598 new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, was killed by %s.", &op->name, &hitter->name);
1618 } 1599 }
1619 1600
1620 remove_friendly_object (op); 1601 remove_friendly_object (op);
1621 } 1602 }
1622 1603
1623 op->destroy (); 1604 op->drop_and_destroy ();
1624 } 1605 }
1625 else 1606 else
1626 /* Player has been killed! */ 1607 /* Player has been killed! */
1627 op->contr->killer = owner->type == PLAYER ? owner : hitter; 1608 op->contr->killer = owner->type == PLAYER ? owner : hitter;
1628 1609
1788 */ 1769 */
1789 if (type & AT_HOLYWORD) 1770 if (type & AT_HOLYWORD)
1790 { 1771 {
1791 object *god; 1772 object *god;
1792 1773
1793 if ((!hitter->slaying || 1774 if ((!hitter->slaying
1794 (!(op->race && strstr (hitter->slaying, op->race)) && 1775 || (!(op->race && hitter->slaying.contains (op->race))
1795 !(op->name && strstr (hitter->slaying, op->name)))) && 1776 && !(op->name && hitter->slaying.contains (op->name))))
1796 (!QUERY_FLAG (op, FLAG_UNDEAD) || 1777 && (!QUERY_FLAG (op, FLAG_UNDEAD)
1797 (hitter->title != NULL 1778 || (hitter->title
1798 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, shstr_undead) != NULL))) 1779 && (god = find_god (determine_god (hitter))) != NULL
1780 && god->race
1781 && god->race.contains (shstr_undead))))
1799 return 0; 1782 return 0;
1800 } 1783 }
1801 1784
1802 maxattacktype = type; /* initialise this to something */ 1785 maxattacktype = type; /* initialise this to something */
1803 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) 1786 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum)
1914 /* See if the creature has been killed */ 1897 /* See if the creature has been killed */
1915 rtn_kill = kill_object (op, maxdam, hitter, type); 1898 rtn_kill = kill_object (op, maxdam, hitter, type);
1916 if (rtn_kill != -1) 1899 if (rtn_kill != -1)
1917 return rtn_kill; 1900 return rtn_kill;
1918 1901
1919
1920 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note 1902 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note
1921 * that before if the player was immune to ghosthit, the monster 1903 * that before if the player was immune to ghosthit, the monster
1922 * remained - that is no longer the case. 1904 * remained - that is no longer the case.
1923 */ 1905 */
1924 if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) 1906 if (QUERY_FLAG (hitter, FLAG_ONE_HIT))
1925 hitter->destroy (); 1907 hitter->drop_and_destroy ();
1926
1927 /* Lets handle creatures that are splitting now */ 1908 /* Lets handle creatures that are splitting now */
1928 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) 1909 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING))
1929 { 1910 {
1930 int i; 1911 int i;
1931 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); 1912 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY);
1971 } 1952 }
1972 1953
1973 op->destroy (); 1954 op->destroy ();
1974 } 1955 }
1975 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) 1956 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10)
1976 hitter->destroy (); 1957 hitter->drop_and_destroy ();
1977 1958
1978 return maxdam; 1959 return maxdam;
1979} 1960}
1980 1961
1981void 1962void
2178 ** field of the deathstriking object */ 2159 ** field of the deathstriking object */
2179 2160
2180 int atk_lev, def_lev, kill_lev; 2161 int atk_lev, def_lev, kill_lev;
2181 2162
2182 if (hitter->slaying) 2163 if (hitter->slaying)
2183 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && strstr (hitter->slaying, shstr_undead)) || (op->race && strstr (hitter->slaying, op->race)))) 2164 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead))
2165 || (op->race && hitter->slaying.contains (op->race))))
2184 return; 2166 return;
2185 2167
2186 def_lev = op->level; 2168 def_lev = op->level;
2187 if (def_lev < 1) 2169 if (def_lev < 1)
2188 { 2170 {
2189 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->archname, &op->name); 2171 LOG (llevError, "BUG: arch %s with level < 1 (%s)\n", &op->arch->archname, op->debug_desc ());
2190 def_lev = 1; 2172 def_lev = 1;
2191 } 2173 }
2192 2174
2193 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2; 2175 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2;
2194 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", 2176 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n",
2287 { 2269 {
2288 /* target is unseen */ 2270 /* target is unseen */
2289 if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) 2271 if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND))
2290 adjust -= 10; 2272 adjust -= 10;
2291 /* dark map penalty for the hitter (lacks infravision if we got here). */ 2273 /* dark map penalty for the hitter (lacks infravision if we got here). */
2292 else if (target->map && target->map->darkness > 0 && !stand_in_light (target)) 2274 else if (!stand_in_light (target))
2293 adjust -= target->map->darkness; 2275 adjust -= target->map->darklevel ();
2294 } 2276 }
2295 2277
2296 if (QUERY_FLAG (attacker, FLAG_SCARED)) 2278 if (QUERY_FLAG (attacker, FLAG_SCARED))
2297 adjust -= 3; 2279 adjust -= 3;
2298 2280

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines