attack_prediction.hpp

Go to the documentation of this file.
00001 /* $Id: attack_prediction.hpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2007 - 2008
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file attack_prediction.hpp
00016 //!
00017 
00018 #ifndef ATTACK_PREDICTION_H_INCLUDED
00019 #define ATTACK_PREDICTION_H_INCLUDED
00020 
00021 #include "global.hpp"
00022 
00023 #include <vector>
00024 #include "actions.hpp"
00025 
00026 // This encapsulates all we need to know for this combat.
00027 //! All combat-related infos.
00028 struct combatant
00029 {
00030     //! Construct a combatant.
00031     combatant(const battle_context::unit_stats &u, const combatant *prev = NULL);
00032 
00033     //! Copy constructor
00034     combatant(const combatant &that, const battle_context::unit_stats &u);
00035 
00036     //! Simulate a fight!  Can be called multiple times for cumulative calculations.
00037     void fight(combatant &opponent);
00038 
00039     //! Resulting probability distribution (may NOT be as large as max_hp)
00040     std::vector<double> hp_dist;
00041 
00042     //! Resulting chance we were not hit by this opponent (important if it poisons)
00043     double untouched;
00044 
00045     //! Resulting chance we are poisoned.
00046     double poisoned;
00047 
00048     //! Resulting chance we are slowed.
00049     double slowed;
00050 
00051     //! What's the average hp (weighted average of hp_dist).
00052     double average_hp(unsigned int healing = 0) const;
00053 
00054 private:
00055     combatant(const combatant &that);
00056     combatant& operator=(const combatant &);
00057 
00058     //! Minimum hp we could possibly have.
00059     unsigned min_hp() const;
00060 
00061     //! HP distribution we could end up with.
00062     static unsigned hp_dist_size(const battle_context::unit_stats &u, const combatant *prev);
00063 
00064     //! Combat without chance of death, berserk, slow or drain is simple.
00065     void no_death_fight(combatant &opponent);
00066 
00067     //! Combat with <= 1 strike each is simple, too.
00068     void one_strike_fight(combatant &opponent);
00069 
00070     //! All other cases.
00071     void complex_fight(combatant &opponent, unsigned int rounds);
00072 
00073     //! We must adjust for swarm after every combat.
00074     void adjust_hitchance();
00075 
00076     const battle_context::unit_stats &u_;
00077 
00078     //! Usually uniform, but if we have swarm, then can be different.
00079     std::vector<double> hit_chances_;
00080 
00081     //! Summary of matrix used to calculate last battle (unslowed & slowed).
00082     std::vector<double> summary[2];
00083 };
00084 
00085 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs