attack_prediction.hpp

Go to the documentation of this file.
00001 /* $Id: attack_prediction.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2007 - 2012
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 as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /** @file */
00017 
00018 #ifndef ATTACK_PREDICTION_H_INCLUDED
00019 #define ATTACK_PREDICTION_H_INCLUDED
00020 
00021 #include "global.hpp"
00022 
00023 #include <vector>
00024 
00025 #include <cstring>
00026 
00027 struct battle_context_unit_stats;
00028 
00029 // This encapsulates all we need to know for this combat.
00030 /** All combat-related info. */
00031 struct combatant
00032 {
00033     /** Construct a combatant. */
00034     combatant(const battle_context_unit_stats &u, const combatant *prev = NULL);
00035 
00036     /** Copy constructor */
00037     combatant(const combatant &that, const battle_context_unit_stats &u);
00038 
00039     /** Simulate a fight!  Can be called multiple times for cumulative calculations. */
00040     void fight(combatant &opponent, bool levelup_considered=true);
00041 
00042     /** Resulting probability distribution (may NOT be as large as max_hp) */
00043     std::vector<double> hp_dist;
00044 
00045     /** Resulting chance we were not hit by this opponent (important if it poisons) */
00046     double untouched;
00047 
00048     /** Resulting chance we are poisoned. */
00049     double poisoned;
00050 
00051     /** Resulting chance we are slowed. */
00052     double slowed;
00053 
00054     /** What's the average hp (weighted average of hp_dist). */
00055     double average_hp(unsigned int healing = 0) const;
00056 
00057 private:
00058     combatant(const combatant &that);
00059     combatant& operator=(const combatant &);
00060 
00061     /** Minimum hp we could possibly have. */
00062     unsigned min_hp() const;
00063 
00064     /** HP distribution we could end up with. */
00065     static unsigned hp_dist_size(const battle_context_unit_stats &u, const combatant *prev);
00066 
00067     /** Combat without chance of death, berserk, slow or drain is simple. */
00068     void no_death_fight(combatant &opponent, bool levelup_considered);
00069 
00070     /** Combat with <= 1 strike each is simple, too. */
00071     void one_strike_fight(combatant &opponent, bool levelup_considered);
00072 
00073     /** All other cases. */
00074     void complex_fight(combatant &opponent, unsigned rounds, bool levelup_considered);
00075 
00076     /** We must adjust for swarm after every combat. */
00077     void adjust_hitchance();
00078 
00079     const battle_context_unit_stats &u_;
00080 
00081     /** Usually uniform, but if we have swarm, then can be different. */
00082     std::vector<double> hit_chances_;
00083 
00084     /** Summary of matrix used to calculate last battle (unslowed & slowed). */
00085     std::vector<double> summary[2];
00086 };
00087 
00088 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:34 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs