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.66 by root, Mon May 28 21:28:35 2007 UTC vs.
Revision 1.78 by root, Mon Oct 22 03:11:46 2007 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * 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, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * 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 along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include <assert.h> 24#include <assert.h>
87 break; 86 break;
88 } 87 }
89 else 88 else
90 mt = name_to_material (op->materialname); 89 mt = name_to_material (op->materialname);
91 90
92 if (mt == NULL) 91 if (!mt)
93 return TRUE; 92 return TRUE;
94 93
95 roll = rndm (1, 20); 94 roll = rndm (1, 20);
96 95
97 /* the attacktypes have no meaning for object saves 96 /* the attacktypes have no meaning for object saves
162 * function if the object doesnt contain a material that can burn. 161 * function if the object doesnt contain a material that can burn.
163 * So forget lighting magical swords on fire with this!) -b.t. 162 * So forget lighting magical swords on fire with this!) -b.t.
164 */ 163 */
165 if (type & (AT_FIRE | AT_ELECTRICITY) && op->other_arch && QUERY_FLAG (op, FLAG_IS_LIGHTABLE)) 164 if (type & (AT_FIRE | AT_ELECTRICITY) && op->other_arch && QUERY_FLAG (op, FLAG_IS_LIGHTABLE))
166 { 165 {
167 const char *arch = op->other_arch->name; 166 const char *arch = op->other_arch->archname;
168 167
169 op = decrease_ob_nr (op, 1); 168 op = decrease_ob_nr (op, 1);
170 169
171 if (op) 170 if (op)
172 fix_stopped_item (op, m, originator); 171 fix_stopped_item (op, m, originator);
283 return 0; 282 return 0;
284 } 283 }
285 284
286 if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) 285 if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL)
287 { 286 {
288 LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->name, &op->name); 287 LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name);
289 return 0; 288 return 0;
290 } 289 }
291 290
292 if (!op->map) 291 if (!op->map)
293 { 292 {
614 if (hitter->owner != NULL) 613 if (hitter->owner != NULL)
615 sprintf (buf, "%s's %s%s you.", &hitter->owner->name, &hitter->name, buf2); 614 sprintf (buf, "%s's %s%s you.", &hitter->owner->name, &hitter->name, buf2);
616 else 615 else
617 { 616 {
618 sprintf (buf, "%s%s you.", &hitter->name, buf2); 617 sprintf (buf, "%s%s you.", &hitter->name, buf2);
618
619 if (dam != 0) 619 if (dam != 0)
620 { 620 {
621 if (dam < 10) 621 if (dam < 10)
622 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT1, 0, 0); 622 op->contr->play_sound (sound_find ("player_is_hit1"));
623 else if (dam < 20) 623 else if (dam < 20)
624 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT2, 0, 0); 624 op->contr->play_sound (sound_find ("player_is_hit2"));
625 else 625 else
626 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT3, 0, 0); 626 op->contr->play_sound (sound_find ("player_is_hit3"));
627 } 627 }
628 } 628 }
629
629 new_draw_info (NDI_BLACK, 0, op, buf); 630 new_draw_info (NDI_BLACK, 0, op, buf);
630 } /* end of player hitting player */ 631 } /* end of player hitting player */
631 632
632 if (hitter->type == PLAYER) 633 if (hitter->type == PLAYER)
633 { 634 {
634 sprintf (buf, "You %s.", buf1); 635 sprintf (buf, "You %s.", buf1);
636
635 if (dam != 0) 637 if (dam != 0)
636 { 638 {
637 if (dam < 10) 639 if (dam < 10)
638 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS1, 0, 0); 640 op->play_sound (sound_find ("player_hits1"));
639 else if (dam < 20) 641 else if (dam < 20)
640 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS2, 0, 0); 642 op->play_sound (sound_find ("player_hits2"));
641 else 643 else
642 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS3, 0, 0); 644 op->play_sound (sound_find ("player_hits3"));
643 } 645 }
646
644 new_draw_info (NDI_BLACK, 0, hitter, buf); 647 new_draw_info (NDI_BLACK, 0, hitter, buf);
645 } 648 }
646 else if (hitter->owner != NULL && hitter->owner->type == PLAYER) 649 else if (hitter->owner != NULL && hitter->owner->type == PLAYER)
647 { 650 {
648 /* look for stacked spells and start reducing the message chances */ 651 /* look for stacked spells and start reducing the message chances */
657 if (next) 660 if (next)
658 while (next) 661 while (next)
659 { 662 {
660 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE)) 663 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE))
661 i *= 3; 664 i *= 3;
665
662 tmp = next; 666 tmp = next;
663 next = tmp->above; 667 next = tmp->above;
664 } 668 }
665 669
666 if (i < 0) 670 if (i < 0)
671 } 675 }
672 else if (rndm (0, 5) != 0) 676 else if (rndm (0, 5) != 0)
673 return; 677 return;
674 678
675 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name); 679 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name);
676 play_sound_map (op->map, op->x, op->y, SOUND_PLAYER_HITS4); 680 op->play_sound (sound_find ("player_hits4"));
677 new_draw_info (NDI_BLACK, 0, hitter->owner, buf); 681 new_draw_info (NDI_BLACK, 0, hitter->owner, buf);
678 } 682 }
679} 683}
680 684
681 685
685 if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) 689 if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED))
686 { 690 {
687 LOG (llevError, "BUG: get_attack_mode(): freed object\n"); 691 LOG (llevError, "BUG: get_attack_mode(): freed object\n");
688 return 1; 692 return 1;
689 } 693 }
694
690 if ((*target)->head) 695 if ((*target)->head)
691 *target = (*target)->head; 696 *target = (*target)->head;
697
692 if ((*hitter)->head) 698 if ((*hitter)->head)
693 *hitter = (*hitter)->head; 699 *hitter = (*hitter)->head;
700
694 if ((*hitter)->env != NULL || (*target)->env != NULL) 701 if ((*hitter)->env != NULL || (*target)->env != NULL)
695 { 702 {
696 *simple_attack = 1; 703 *simple_attack = 1;
697 return 0; 704 return 0;
698 } 705 }
706
699 if (QUERY_FLAG (*target, FLAG_REMOVED) 707 if (QUERY_FLAG (*target, FLAG_REMOVED)
700 || QUERY_FLAG (*hitter, FLAG_REMOVED) || (*hitter)->map == NULL || !on_same_map ((*hitter), (*target))) 708 || QUERY_FLAG (*hitter, FLAG_REMOVED)
709 || !(*hitter)->map
710 || !on_same_map (*hitter, *target))
701 { 711 {
702 LOG (llevError, "BUG: hitter (arch %s, name %s) with no relation to " "target\n", &(*hitter)->arch->name, &(*hitter)->name); 712 LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n",
713 (*hitter)->debug_desc (), (*target)->debug_desc ());
703 return 1; 714 return 1;
704 } 715 }
716
705 *simple_attack = 0; 717 *simple_attack = 0;
706 return 0; 718 return 0;
707} 719}
708 720
709static int 721static int
1081 return dam; 1093 return dam;
1082 1094
1083 if (hitter->slaying) 1095 if (hitter->slaying)
1084 { 1096 {
1085 if ((op->race && strstr (hitter->slaying, op->race)) 1097 if ((op->race && strstr (hitter->slaying, op->race))
1086 || (op->arch && op->arch->name && strstr (op->arch->name, hitter->slaying))) 1098 || (op->arch && op->arch->archname && strstr (op->arch->archname, hitter->slaying)))
1087 { 1099 {
1088 doesnt_slay = 0; 1100 doesnt_slay = 0;
1089 dam *= 3; 1101 dam *= 3;
1090 } 1102 }
1091 } 1103 }
1290 object *god = find_god (determine_god (owner)); 1302 object *god = find_god (determine_god (owner));
1291 int div = 1; 1303 int div = 1;
1292 1304
1293 /* if undead are not an enemy of your god, you turn them 1305 /* if undead are not an enemy of your god, you turn them
1294 * at half strength */ 1306 * at half strength */
1295 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL) 1307 if (!god || !god->slaying || strstr (god->slaying, shstr_undead) == NULL)
1296 div = 2; 1308 div = 2;
1297 1309
1298 /* Give a bonus if you resist turn undead */ 1310 /* Give a bonus if you resist turn undead */
1299 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100))) 1311 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100)))
1300 scare_creature (op, owner); 1312 scare_creature (op, owner);
1475 else 1487 else
1476 new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s.", query_name (op)); 1488 new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s.", query_name (op));
1477 1489
1478 /* Only play sounds for melee kills */ 1490 /* Only play sounds for melee kills */
1479 if (hitter->type == PLAYER) 1491 if (hitter->type == PLAYER)
1480 play_sound_map (owner->map, owner->x, owner->y, SOUND_PLAYER_KILLS); 1492 owner->play_sound (sound_find ("player_kills"));
1481 } 1493 }
1482 1494
1483 /* If a player kills another player, not on 1495 /* If a player kills another player, not on
1484 * battleground, the "killer" looses 1 luck. Since this is 1496 * battleground, the "killer" looses 1 luck. Since this is
1485 * not reversible, it's actually quite a pain IMHO. -AV 1497 * not reversible, it's actually quite a pain IMHO. -AV
1621 { 1633 {
1622 object *owner1 = op->owner; 1634 object *owner1 = op->owner;
1623 1635
1624 if (owner1 && owner1->type == PLAYER) 1636 if (owner1 && owner1->type == PLAYER)
1625 { 1637 {
1626 play_sound_player_only (owner1->contr, SOUND_PET_IS_KILLED, 0, 0); 1638 owner1->contr->play_sound (sound_find ("pet_is_killed"));
1627 /* Maybe we should include the owner that killed this, maybe not */ 1639 /* Maybe we should include the owner that killed this, maybe not */
1628 new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, is killed by %s.", &op->name, &hitter->name); 1640 new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, is killed by %s.", &op->name, &hitter->name);
1629 } 1641 }
1630 1642
1631 remove_friendly_object (op); 1643 remove_friendly_object (op);
1680 friendlyfire = 0; 1692 friendlyfire = 0;
1681 } 1693 }
1682 1694
1683 return friendlyfire; 1695 return friendlyfire;
1684} 1696}
1685
1686 1697
1687/* This isn't used just for players, but in fact most objects. 1698/* This isn't used just for players, but in fact most objects.
1688 * op is the object to be hit, dam is the amount of damage, hitter 1699 * op is the object to be hit, dam is the amount of damage, hitter
1689 * is what is hitting the object, type is the attacktype, and 1700 * is what is hitting the object, type is the attacktype, and
1690 * full_hit is set if monster area does not matter. 1701 * full_hit is set if monster area does not matter.
1810 if ((!hitter->slaying || 1821 if ((!hitter->slaying ||
1811 (!(op->race && strstr (hitter->slaying, op->race)) && 1822 (!(op->race && strstr (hitter->slaying, op->race)) &&
1812 !(op->name && strstr (hitter->slaying, op->name)))) && 1823 !(op->name && strstr (hitter->slaying, op->name)))) &&
1813 (!QUERY_FLAG (op, FLAG_UNDEAD) || 1824 (!QUERY_FLAG (op, FLAG_UNDEAD) ||
1814 (hitter->title != NULL 1825 (hitter->title != NULL
1815 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, undead_name) != NULL))) 1826 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, shstr_undead) != NULL)))
1816 return 0; 1827 return 0;
1817 } 1828 }
1818 1829
1819 maxattacktype = type; /* initialise this to something */ 1830 maxattacktype = type; /* initialise this to something */
1820 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) 1831 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum)
1861#endif 1872#endif
1862 } 1873 }
1863 1874
1864 if (!full_hit) 1875 if (!full_hit)
1865 { 1876 {
1866 archetype *at;
1867 int area; 1877 int area;
1868 int remainder; 1878 int remainder;
1869 1879
1870 area = 0; 1880 area = 0;
1871 for (at = op->arch; at != NULL; at = at->more) 1881
1882 for (archetype *at = op->arch; at; at = (archetype *)at->more)
1872 area++; 1883 area++;
1884
1873 assert (area > 0); 1885 assert (area > 0);
1874 1886
1875 /* basically: maxdam /= area; we try to "simulate" a float 1887 /* basically: maxdam /= area; we try to "simulate" a float
1876 value-effect */ 1888 value-effect */
1877 remainder = 100 * (maxdam % area) / area; 1889 remainder = 100 * (maxdam % area) / area;
1954 return maxdam; 1966 return maxdam;
1955 } 1967 }
1956 1968
1957 op->remove (); 1969 op->remove ();
1958 1970
1959 for (i = 0; i < NROFNEWOBJS (op); i++) 1971 for (i = 0; i < op->stats.food; i++)
1960 { /* This doesn't handle op->more yet */ 1972 { /* This doesn't handle op->more yet */
1961 object *tmp = arch_to_object (op->other_arch); 1973 object *tmp = arch_to_object (op->other_arch);
1962 int j; 1974 int j;
1963 1975
1964 tmp->stats.hp = op->stats.hp; 1976 tmp->stats.hp = op->stats.hp;
2036 tmp->stats.Dex = MAX (-(dam / 6 + 1), -10); 2048 tmp->stats.Dex = MAX (-(dam / 6 + 1), -10);
2037 tmp->stats.Int = MAX (-dam / 7, -10); 2049 tmp->stats.Int = MAX (-dam / 7, -10);
2038 SET_FLAG (tmp, FLAG_APPLIED); 2050 SET_FLAG (tmp, FLAG_APPLIED);
2039 op->update_stats (); 2051 op->update_stats ();
2040 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); 2052 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill.");
2053 op->play_sound (tmp->sound);
2041 } 2054 }
2042 2055
2043 if (hitter->type == PLAYER) 2056 if (hitter->type == PLAYER)
2044 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); 2057 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name);
2045 else if (hitter->owner != NULL && hitter->owner->type == PLAYER) 2058 else if (hitter->owner != NULL && hitter->owner->type == PLAYER)
2193 ** field of the deathstriking object */ 2206 ** field of the deathstriking object */
2194 2207
2195 int atk_lev, def_lev, kill_lev; 2208 int atk_lev, def_lev, kill_lev;
2196 2209
2197 if (hitter->slaying) 2210 if (hitter->slaying)
2198 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && strstr (hitter->slaying, undead_name)) || (op->race && strstr (hitter->slaying, op->race)))) 2211 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && strstr (hitter->slaying, shstr_undead)) || (op->race && strstr (hitter->slaying, op->race))))
2199 return; 2212 return;
2200 2213
2201 def_lev = op->level; 2214 def_lev = op->level;
2202 if (def_lev < 1) 2215 if (def_lev < 1)
2203 { 2216 {
2204 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->name, &op->name); 2217 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->archname, &op->name);
2205 def_lev = 1; 2218 def_lev = 1;
2206 } 2219 }
2207 2220
2208 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2; 2221 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2;
2209 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", 2222 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines