Sew attack_prediction code into the Makefile.am,
and expose through header (decker2's changes coming soon).
This commit is contained in:
parent
3232c4a57a
commit
2c6e8a3bc5
3 changed files with 62 additions and 52 deletions
|
@ -43,6 +43,7 @@ wesnoth_SOURCES = \
|
|||
ai_python.cpp \
|
||||
animated.cpp \
|
||||
astarnode.cpp \
|
||||
attack_prediction.cpp \
|
||||
builder.cpp \
|
||||
cavegen.cpp \
|
||||
checksum.cpp \
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "global.hpp"
|
||||
#include "wassert.hpp"
|
||||
#include "attack_prediction.hpp"
|
||||
|
||||
// Compile with -O3 -DBENCHMARK for speed testing, -DCHECK for testing
|
||||
// correctness (run tools/wesnoth-attack-sim.c --check on output)
|
||||
|
@ -422,58 +423,6 @@ void prob_matrix::receive_blow_a(unsigned damage, double hit_chance,
|
|||
}
|
||||
}
|
||||
|
||||
// This encapsulates all we need to know for this combat.
|
||||
struct combatant
|
||||
{
|
||||
// Construct a combatant.
|
||||
// As an optimization, if it has no weapons which could drain,
|
||||
// we can simply never calculate hitpoints > current hp.
|
||||
combatant(unsigned hp, unsigned max_hp, bool slowed,
|
||||
bool could_ever_drain = true);
|
||||
|
||||
// Select a weapon.
|
||||
void set_weapon(unsigned num_attacks, bool drains, bool berserk,
|
||||
bool swarm, bool firststrike);
|
||||
|
||||
// Set effect against this particular opponent.
|
||||
void set_effectiveness(unsigned damage, double hit_chance, bool slows);
|
||||
|
||||
// Fight!
|
||||
void fight(combatant &opponent);
|
||||
|
||||
// Only used in benchmarking.
|
||||
void reset();
|
||||
void print(const char label[], unsigned int battle) const;
|
||||
|
||||
// Resulting probability distribution (may NOT be as large as max_hp)
|
||||
std::vector<double> hp_dist;
|
||||
|
||||
// Resulting chance we were not hit by this opponent (important if
|
||||
// it poisons)
|
||||
double untouched;
|
||||
|
||||
private:
|
||||
// How many attacks? (Matters for swarm).
|
||||
unsigned num_attacks(unsigned int hp) const;
|
||||
|
||||
// Usually uniform, but if we have swarm, then can be different.
|
||||
std::vector<double> hit_chances_;
|
||||
double base_hit_chance_;
|
||||
|
||||
// Starting hitpoints, max hp.
|
||||
unsigned hp_, max_hp_;
|
||||
|
||||
// Are we slowed already? (Halves damage, can't be slowed again).
|
||||
bool slowed_;
|
||||
|
||||
// Weapon stats.
|
||||
unsigned base_num_attacks_, damage_;
|
||||
bool drains_, slows_, berserk_, swarm_, firststrike_;
|
||||
|
||||
// Summary of matrix used to calculate last battle (unslowed & slowed).
|
||||
std::vector<double> summary[2];
|
||||
};
|
||||
|
||||
combatant::combatant(unsigned hp, unsigned max_hp, bool slowed,
|
||||
bool could_ever_drain)
|
||||
: hp_dist(could_ever_drain ? max_hp+1: hp+1), hp_(hp), max_hp_(max_hp),
|
||||
|
|
60
src/attack_prediction.hpp
Normal file
60
src/attack_prediction.hpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* $Id$ */
|
||||
|
||||
#ifndef ATTACK_PREDICTION_H_INCLUDED
|
||||
#define ATTACK_PREDICTION_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
// This encapsulates all we need to know for this combat.
|
||||
struct combatant
|
||||
{
|
||||
// Construct a combatant.
|
||||
// As an optimization, if it has no weapons which could drain,
|
||||
// we can simply never calculate hitpoints > current hp.
|
||||
combatant(unsigned hp, unsigned max_hp, bool slowed,
|
||||
bool could_ever_drain = true);
|
||||
|
||||
// Select a weapon.
|
||||
void set_weapon(unsigned num_attacks, bool drains, bool berserk,
|
||||
bool swarm, bool firststrike);
|
||||
|
||||
// Set effect against this particular opponent.
|
||||
void set_effectiveness(unsigned damage, double hit_chance, bool slows);
|
||||
|
||||
// Fight!
|
||||
void fight(combatant &opponent);
|
||||
|
||||
// Only used in benchmarking.
|
||||
void reset();
|
||||
void print(const char label[], unsigned int battle) const;
|
||||
|
||||
// Resulting probability distribution (may NOT be as large as max_hp)
|
||||
std::vector<double> hp_dist;
|
||||
|
||||
// Resulting chance we were not hit by this opponent (important if
|
||||
// it poisons)
|
||||
double untouched;
|
||||
|
||||
private:
|
||||
// How many attacks? (Matters for swarm).
|
||||
unsigned num_attacks(unsigned int hp) const;
|
||||
|
||||
// Usually uniform, but if we have swarm, then can be different.
|
||||
std::vector<double> hit_chances_;
|
||||
double base_hit_chance_;
|
||||
|
||||
// Starting hitpoints, max hp.
|
||||
unsigned hp_, max_hp_;
|
||||
|
||||
// Are we slowed already? (Halves damage, can't be slowed again).
|
||||
bool slowed_;
|
||||
|
||||
// Weapon stats.
|
||||
unsigned base_num_attacks_, damage_;
|
||||
bool drains_, slows_, berserk_, swarm_, firststrike_;
|
||||
|
||||
// Summary of matrix used to calculate last battle (unslowed & slowed).
|
||||
std::vector<double> summary[2];
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue