Reform the monster attacks structure
- Use enum for attack type - Eliminate conversion between new structure form and original integer form
This commit is contained in:
@@ -2306,7 +2306,7 @@ void monster_attack_pc(short who_att,short target) {
|
||||
|
||||
|
||||
|
||||
if((attacker->a[0] != 0) || (attacker->a[2] != 0))
|
||||
if((attacker->a[0].dice != 0) || (attacker->a[2].dice != 0))
|
||||
print_monst_attacks(attacker->number,target);
|
||||
|
||||
// Check sanctuary
|
||||
@@ -2319,7 +2319,7 @@ void monster_attack_pc(short who_att,short target) {
|
||||
}
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
if(attacker->a[i] > 0 && univ.party[target].main_status == eMainStatus::ALIVE) {
|
||||
if(attacker->a[i].dice > 0 && univ.party[target].main_status == eMainStatus::ALIVE) {
|
||||
// sprintf ((char *) create_line, " Attacks %s.",(char *) univ.party[target].name);
|
||||
// add_string_to_buf((char *) create_line);
|
||||
|
||||
@@ -2331,7 +2331,7 @@ void monster_attack_pc(short who_att,short target) {
|
||||
r1 += 5 * univ.party[target].parry;
|
||||
|
||||
// Damage roll
|
||||
r2 = get_ran(attacker->a[i] / 100 + 1,1,attacker->a[i] % 100)
|
||||
r2 = get_ran(attacker->a[i].dice,1,attacker->a[i].sides)
|
||||
+ min(8,attacker->status[eStatus::BLESS_CURSE]) - univ.party[target].status[eStatus::BLESS_CURSE] + 1;
|
||||
if(univ.difficulty_adjust() > 2)
|
||||
r2 = r2 * 2;
|
||||
@@ -2449,10 +2449,10 @@ void monster_attack_monster(short who_att,short attackee) {
|
||||
}
|
||||
|
||||
|
||||
if((attacker->a[1] != 0) || (attacker->a[0] != 0))
|
||||
if((attacker->a[1].dice != 0) || (attacker->a[0].dice != 0))
|
||||
print_monst_attacks(attacker->number,100 + attackee);
|
||||
for(i = 0; i < 3; i++) {
|
||||
if((attacker->a[i] > 0) && (target->active != 0)) {
|
||||
if((attacker->a[i].dice > 0) && (target->active != 0)) {
|
||||
// sprintf ((char *) create_line, " Attacks %s.",(char *) univ.party[target].name);
|
||||
// add_string_to_buf((char *) create_line);
|
||||
|
||||
@@ -2466,7 +2466,7 @@ void monster_attack_monster(short who_att,short attackee) {
|
||||
r1 += 5 * (attacker->status[eStatus::WEBS] / 3);
|
||||
|
||||
// Damage roll
|
||||
r2 = get_ran(attacker->a[i] / 100 + 1,1,attacker->a[i] % 100)
|
||||
r2 = get_ran(attacker->a[i].dice,1,attacker->a[i].sides)
|
||||
+ min(10,attacker->status[eStatus::BLESS_CURSE]) - target->status[eStatus::BLESS_CURSE] + 2;
|
||||
|
||||
if(target->status[eStatus::ASLEEP] > 0 || target->status[eStatus::PARALYZED] > 0) {
|
||||
@@ -4926,26 +4926,25 @@ void add_new_action(short pc_num) {
|
||||
}
|
||||
|
||||
short get_monst_sound(cCreature *attacker,short which_att) {
|
||||
short type,strength;
|
||||
short strength;
|
||||
eMonstMelee type;
|
||||
|
||||
type = attacker->a[which_att].type;
|
||||
strength = attacker->a[which_att];
|
||||
strength = attacker->a[which_att].sides;
|
||||
|
||||
switch(type) {
|
||||
case 3:
|
||||
case eMonstMelee::SLIME:
|
||||
return 11;
|
||||
break;
|
||||
case 4:
|
||||
case eMonstMelee::PUNCH:
|
||||
return 4;
|
||||
break;
|
||||
case 1:
|
||||
case eMonstMelee::CLAW:
|
||||
return 9;
|
||||
break;
|
||||
case 2:
|
||||
case eMonstMelee::BITE:
|
||||
return 10;
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: These sounds don't quite seem right.
|
||||
// They're passed to boom_space, so 0 = ouch, 1 = small sword, 2 = loud sword, 3 = pole, 4 = club
|
||||
if(attacker->m_type == eRace::HUMAN) {
|
||||
if(strength > 9)
|
||||
return 3;
|
||||
@@ -4959,7 +4958,6 @@ short get_monst_sound(cCreature *attacker,short which_att) {
|
||||
if(attacker->m_type == eRace::PRIEST)
|
||||
return 4;
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -391,7 +391,7 @@ static void put_monst_info(cDialog& me, const cCreature& store_m) {
|
||||
}
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
if(store_m.a[i] > 0) {
|
||||
if(store_m.a[i].dice > 0) {
|
||||
if(store_m.a[i].sides == 0) continue;
|
||||
std::ostringstream sout(std::ios_base::ate);
|
||||
sout << store_m.a[i];
|
||||
|
@@ -938,9 +938,9 @@ void print_monst_attacks(mon_num_t m_type,short target) {
|
||||
add_string_to_buf((char *) msg.c_str());
|
||||
}
|
||||
|
||||
void damaged_message(short damage,short type) {
|
||||
void damaged_message(short damage,eMonstMelee type) {
|
||||
std::ostringstream sout;
|
||||
sout << " " << get_str("monster-abilities",130 + type);
|
||||
sout << " " << get_str("monster-abilities",130 + int(type));
|
||||
sout << " for " << damage;
|
||||
add_string_to_buf(sout.str().c_str());
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ std::string get_m_name(mon_num_t num);
|
||||
std::string get_ter_name(ter_num_t num);
|
||||
void print_monst_name(mon_num_t m_type);
|
||||
void print_monst_attacks(mon_num_t m_type,short target);
|
||||
void damaged_message(short damage,short type);
|
||||
void damaged_message(short damage,eMonstMelee type);
|
||||
std::string print_monster_going(mon_num_t m_num,short ap);
|
||||
void monst_spell_note(mon_num_t number,short which_mess);
|
||||
void monst_cast_spell_note(mon_num_t number,eSpell spell);
|
||||
|
@@ -26,9 +26,12 @@ void cMonster::append(legacy::monster_record_type& old){
|
||||
m_health = old.m_health;
|
||||
armor = old.armor;
|
||||
skill = old.skill;
|
||||
for(int i = 0; i < 3; i++) a[i] = old.a[i];
|
||||
a[0].type = old.a1_type;
|
||||
a[1].type = a[2].type = old.a23_type;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
a[i].dice = old.a[i] / 100 + 1;
|
||||
a[i].sides = old.a[i] % 100;
|
||||
}
|
||||
a[0].type = eMonstMelee(old.a1_type);
|
||||
a[1].type = a[2].type = eMonstMelee(old.a23_type);
|
||||
// Unless human, add 3 to the monster's type to get its race
|
||||
// This is because nephil, slith, and vahnatai were inserted
|
||||
if(old.m_type) m_type = eRace(old.m_type + 3);
|
||||
@@ -439,16 +442,6 @@ void cCreature::append(legacy::creature_data_type old){
|
||||
direction = eDirection(old.m_d.direction);
|
||||
}
|
||||
|
||||
cMonster::cAttack::operator int() const {
|
||||
return dice * 100 + sides;
|
||||
}
|
||||
|
||||
cMonster::cAttack& cMonster::cAttack::operator=(int n){
|
||||
dice = n / 100 + 1;
|
||||
sides = n % 100;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const cMonster::cAttack& att) {
|
||||
out << int(att.dice) << 'd' << int(att.sides);
|
||||
return out;
|
||||
@@ -547,6 +540,19 @@ std::istream& operator >> (std::istream& in, eMonstGen& e) {
|
||||
return in;
|
||||
}
|
||||
|
||||
std::ostream& operator << (std::ostream& out, eMonstMelee e) {
|
||||
return out << (int)e;
|
||||
}
|
||||
|
||||
std::istream& operator >> (std::istream& in, eMonstMelee& e) {
|
||||
int i;
|
||||
in >> i;
|
||||
if(i >= 0 && i <= int(eMonstMelee::STAB))
|
||||
e = (eMonstMelee)i;
|
||||
else e = eMonstMelee::PUNCH;
|
||||
return in;
|
||||
}
|
||||
|
||||
std::ostream& operator << (std::ostream& out, eMonstMissile e) {
|
||||
return out << (int)e;
|
||||
}
|
||||
@@ -727,7 +733,7 @@ void cMonster::writeTo(std::ostream& file) const {
|
||||
file << "ARMOR " << int(armor) << '\n';
|
||||
file << "SKILL " << int(skill) << '\n';
|
||||
for(int i = 0; i < 3; i++)
|
||||
file << "ATTACK " << i + 1 << ' ' << int(a[i].dice) << ' ' << int(a[i].sides) << ' ' << int(a[i].type) << '\n';
|
||||
file << "ATTACK " << i + 1 << ' ' << a[i].dice << ' ' << a[i].sides << ' ' << a[i].type << '\n';
|
||||
file << "HEALTH " << int(m_health) << '\n';
|
||||
file << "SPEED " << int(speed) << '\n';
|
||||
file << "MAGE " << int(mu) << '\n';
|
||||
@@ -804,11 +810,8 @@ void cMonster::readFrom(std::istream& file) {
|
||||
m_name = read_maybe_quoted_string(line);
|
||||
} else if(cur == "ATTACK") {
|
||||
int which;
|
||||
line >> which >> temp1 >> temp2 >> temp3;
|
||||
line >> which >> a[which].dice >> a[which].sides >> a[which].type;
|
||||
which--;
|
||||
a[which].dice = temp1;
|
||||
a[which].sides = temp2;
|
||||
a[which].type = temp3;
|
||||
} else if(cur == "SIZE") {
|
||||
line >> temp1 >> temp2;
|
||||
x_width = temp1;
|
||||
|
@@ -111,10 +111,8 @@ union uAbility {
|
||||
class cMonster {
|
||||
public:
|
||||
struct cAttack{
|
||||
unsigned char dice, sides, type;
|
||||
// TODO: Remove the need for these operators by changing the code that uses them
|
||||
operator int() const;
|
||||
cAttack& operator=(int n);
|
||||
unsigned short dice, sides;
|
||||
eMonstMelee type;
|
||||
};
|
||||
unsigned char level;
|
||||
std::string m_name;
|
||||
@@ -198,6 +196,8 @@ std::ostream& operator << (std::ostream& out, eMonstAbil e);
|
||||
std::istream& operator >> (std::istream& in, eMonstAbil& e);
|
||||
std::ostream& operator << (std::ostream& out, eMonstMissile e);
|
||||
std::istream& operator >> (std::istream& in, eMonstMissile& e);
|
||||
std::ostream& operator << (std::ostream& out, eMonstMelee e);
|
||||
std::istream& operator >> (std::istream& in, eMonstMelee& e);
|
||||
std::ostream& operator << (std::ostream& out, eMonstGen e);
|
||||
std::istream& operator >> (std::istream& in, eMonstGen& e);
|
||||
std::ostream& operator << (std::ostream& out, eDirection e);
|
||||
|
Reference in New Issue
Block a user