#if defined(macintosh) #include <types.h> #else #include <sys/types.h> #endif #include <ctype.h> #include <stdio.h> #include <string.h> #include <time.h> #include "merc.h" #include "interp.h" #include "magic.h" #include "recycle.h" #include "tables.h" int thri_get_melee_damage(CHAR_DATA * ch, CHAR_DATA * victim, bool secondary); /* * thri_one_hit() * * Ok, heres the calculations: * * [ 1] Thac0 = attacker->interpolate() * [ 2] Thac0 += victim->armor_class * [ 3] Thac0 -= attacker->base_attack * [ 4] Logging.. * [ 5] Determine hit */ void thri_one_hit (CHAR_DATA * ch, CHAR_DATA * victim, int dt, bool secondary) { int thac0, thac0_00, thac0_32; int diceroll, dam_type; int final_damage; OBJ_DATA * wield; /* Determine Dam type */ if (!secondary) wield = get_eq_char (ch, WEAR_WIELD); else wield = get_eq_char(ch, WEAR_SECONDARY); if (dt == TYPE_UNDEFINED) { dt = TYPE_HIT; if (wield != NULL && wield->item_type == ITEM_WEAPON) dt += wield->value[3]; else dt += ch->dam_type; } if (dt < TYPE_HIT) if (wield != NULL) dam_type = attack_table[wield->value[3]].damage; else dam_type = attack_table[ch->dam_type].damage; else dam_type = attack_table[dt - TYPE_HIT].damage; if (dam_type == -1) dam_type = DAM_BASH; /* [ 1] Determine Thac0 */ if (IS_NPC (ch)) { thac0_00 = 20; thac0_32 = 7; if (IS_SET (ch->act, ACT_WARRIOR)) thac0_32 = 1; else if (IS_SET (ch->act, ACT_THIEF)) thac0_32 = 7; else if (IS_SET (ch->act, ACT_CLERIC)) thac0_32 = 10; else if (IS_SET (ch->act, ACT_MAGE)) thac0_32 = 5; } else { thac0_00 = class_table[ch->class].thac0_00; thac0_32 = class_table[ch->class].thac0_32; } thac0 = interpolate (ch->level, thac0_00, thac0_32); printf_to_char(ch, "Base Thac0: {w%d{x\n", thac0); /* [ 2] Thac0 += victim AC */ thac0 -= victim->armor_class; printf_to_char(ch, "Vict AC: {w%d{x (%d)\n", victim->armor_class, thac0); /* [ 3] Thac0 -= attacker->base_attack */ thac0 -= ch->base_attack; printf_to_char(ch, "Base Atk: {w%d{x (%d)\n", ch->base_attack, thac0); /* [ 4] Determine damage */ final_damage = thri_get_melee_damage(ch, victim, secondary); /* [ 5] Determine hit */ diceroll = dice(1, 20); printf_to_char(ch, "Diceroll = %d\n", diceroll); if (diceroll <= thac0) { /* We have a miss */ printf_to_char(ch, "-------\nMiss\n"); damage (ch, victim, 0, dt, dam_type, TRUE, FALSE); tail_chain (); return; } else { /* We have a Hit baby! */ printf_to_char(ch, "-------\nHIT\n"); damage (ch, victim, final_damage, dt, dam_type, TRUE, FALSE); tail_chain (); return; } tail_chain(); return; } /* * thri_get_melee_damage() * * Returns melee damage */ int thri_get_melee_damage(CHAR_DATA * ch, CHAR_DATA * victim, bool secondary) { int full_dam; OBJ_DATA * wield; /* If Second weapon */ if (!secondary) wield = get_eq_char (ch, WEAR_WIELD); else wield = get_eq_char(ch, WEAR_SECONDARY); /* If null, hand to hand attack, expand later */ if (wield == NULL) full_dam = number_range(1, 2); else { /* Melee Weapon */ full_dam = number_range (wield->value[1], wield->value[2]); } return full_dam; } /* * primary_attack() * * Attacks with primary weapon * * Base: 10 * Second = -2 * Third = -2 * Fourth = -1 * Fifth = -1 */ void primary_attack(CHAR_DATA * ch, CHAR_DATA * victim, int dt) { int next_round; int speed_bonus; next_round = 18; thri_one_hit (ch, victim, dt, FALSE); /* Ok take care of Speed */ speed_bonus = ch->multis[3] / 10; next_round -= speed_bonus; /* Haste */ if (IS_AFFECTED (ch, AFF_HASTE)) next_round = next_round /= 2; ROUND_STATE(ch, next_round); return; } void secondary_attack(CHAR_DATA * ch, CHAR_DATA * victim, int dt) { int next_round; int speed_bonus; next_round = 22; if (get_eq_char (victim, WEAR_SECONDARY) == NULL) return; thri_one_hit (ch, victim, dt, TRUE); /* Ok take care of Speed */ speed_bonus = ch->multis[3] / 10; next_round -= speed_bonus; /* Haste */ if (IS_AFFECTED (ch, AFF_HASTE)) next_round = next_round /= 2 + 2; ch->round2 = next_round; return; }