mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-03 01:45:41 +00:00
AI refactoring: moved event objects location to ai_manager...
...(no reason to keep one copy per ai, since only playsingle_controller is an observer). Interface for raising those events from the ai unchanged (no reason to change it)
This commit is contained in:
parent
8fb7a029db
commit
373d73e576
@ -400,19 +400,6 @@ const ai_interface::info& ai_interface::get_info() const{
|
||||
return ai_manager::get_active_ai_info_for_side(get_side());
|
||||
}
|
||||
|
||||
void ai_interface::raise_user_interact()
|
||||
{
|
||||
const int interact_time = 30;
|
||||
const int time_since_interact = SDL_GetTicks() - last_interact_;
|
||||
if(time_since_interact < interact_time) {
|
||||
return;
|
||||
}
|
||||
|
||||
user_interact_.notify_observers();
|
||||
|
||||
last_interact_ = SDL_GetTicks();
|
||||
}
|
||||
|
||||
void ai_interface::diagnostic(const std::string& msg)
|
||||
{
|
||||
if(game_config::debug) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "ai_actions.hpp"
|
||||
#include "ai_interface.hpp"
|
||||
#include "ai_manager.hpp"
|
||||
|
||||
#define DBG_AI LOG_STREAM(debug, ai)
|
||||
#define LOG_AI LOG_STREAM(info, ai)
|
||||
@ -28,6 +29,26 @@
|
||||
// =======================================================================
|
||||
//
|
||||
// =======================================================================
|
||||
void ai_interface::raise_user_interact() const
|
||||
{
|
||||
ai_manager::raise_user_interact();
|
||||
}
|
||||
|
||||
void ai_interface::raise_unit_recruited() const
|
||||
{
|
||||
ai_manager::raise_unit_recruited();
|
||||
}
|
||||
|
||||
void ai_interface::raise_unit_moved() const
|
||||
{
|
||||
ai_manager::raise_unit_moved();
|
||||
}
|
||||
|
||||
void ai_interface::raise_enemy_attacked() const
|
||||
{
|
||||
ai_manager::raise_enemy_attacked();
|
||||
}
|
||||
|
||||
|
||||
std::auto_ptr<ai_attack_result> ai_interface::execute_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon){
|
||||
return ai_actions::execute_attack_action(get_side(),true,attacker_loc,defender_loc,attacker_weapon);
|
||||
@ -63,3 +84,4 @@ std::auto_ptr<ai_stopunit_result> ai_interface::execute_stopunit_action(const ma
|
||||
std::auto_ptr<ai_stopunit_result> ai_interface::check_stopunit_action(const map_location& unit_location, bool remove_movement, bool remove_attacks){
|
||||
return ai_actions::execute_stopunit_action(get_side(),false,unit_location,remove_movement,remove_attacks);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ class game_display;
|
||||
class gamemap;
|
||||
|
||||
#include "../formula_callable.hpp"
|
||||
#include "../generic_event.hpp"
|
||||
#include "../pathfind.hpp"
|
||||
#include "../gamestatus.hpp"
|
||||
#include "../playturn.hpp"
|
||||
@ -89,9 +88,7 @@ public:
|
||||
* All derived classes should take an argument of type info& which they
|
||||
* should pass to this constructor.
|
||||
*/
|
||||
ai_interface(int side, bool master) : side_(side), master_(master), last_interact_(0), user_interact_("ai_user_interact"),
|
||||
unit_recruited_("ai_unit_recruited"), unit_moved_("ai_unit_moved"),
|
||||
enemy_attacked_("ai_enemy_attacked") {
|
||||
ai_interface(int side, bool master) : side_(side), master_(master) {
|
||||
add_ref(); //this class shouldn't be reference counted.
|
||||
}
|
||||
virtual ~ai_interface() {}
|
||||
@ -107,7 +104,6 @@ public:
|
||||
* Derived persistant AIs should call this function each turn (expect first)
|
||||
*/
|
||||
virtual void new_turn() {
|
||||
last_interact_ = 0;
|
||||
}
|
||||
|
||||
/** Return a reference to the 'team' object for the AI. */
|
||||
@ -120,12 +116,6 @@ public:
|
||||
/** Display a debug message as a chat message. */
|
||||
void log_message(const std::string& msg);
|
||||
|
||||
// Exposes events to allow for attaching/detaching handlers.
|
||||
events::generic_event& user_interact() { return user_interact_; }
|
||||
events::generic_event& unit_recruited() { return unit_recruited_; }
|
||||
events::generic_event& unit_moved() { return unit_moved_; }
|
||||
events::generic_event& enemy_attacked() { return enemy_attacked_; }
|
||||
|
||||
/** Set the side */
|
||||
virtual void set_side(unsigned int side) { side_ = side; }
|
||||
|
||||
@ -292,23 +282,18 @@ protected:
|
||||
* doesn't occur too often, so there is no problem with calling it very
|
||||
* regularly.
|
||||
*/
|
||||
void raise_user_interact();
|
||||
void raise_user_interact() const;
|
||||
|
||||
/** Notifies all interested observers of the event respectively. */
|
||||
void raise_unit_recruited() { unit_recruited_.notify_observers(); }
|
||||
void raise_unit_moved() { unit_moved_.notify_observers(); }
|
||||
void raise_enemy_attacked() { enemy_attacked_.notify_observers(); }
|
||||
void raise_unit_recruited() const;
|
||||
void raise_unit_moved() const;
|
||||
void raise_enemy_attacked() const;
|
||||
protected:
|
||||
virtual void get_inputs(std::vector<game_logic::formula_input>* inputs) const;
|
||||
virtual variant get_value(const std::string& key) const;
|
||||
private:
|
||||
unsigned int side_;
|
||||
bool master_;
|
||||
int last_interact_;
|
||||
events::generic_event user_interact_;
|
||||
events::generic_event unit_recruited_;
|
||||
events::generic_event unit_moved_;
|
||||
events::generic_event enemy_attacked_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -288,7 +288,7 @@ void ai_manager::remove_observer(events::observer* event_observer){
|
||||
enemy_attacked_.detach_handler(event_observer);
|
||||
}
|
||||
|
||||
void ai_manager::raise_unit_interact() {
|
||||
void ai_manager::raise_user_interact() {
|
||||
const int interact_time = 30;
|
||||
const int time_since_interact = SDL_GetTicks() - last_interact_;
|
||||
if(time_since_interact < interact_time) {
|
||||
@ -688,10 +688,6 @@ void ai_manager::set_active_ai_algorithm_type_for_side( int side, const std::str
|
||||
void ai_manager::play_turn( int side, events::observer* event_observer ){
|
||||
last_interact_ = 0;
|
||||
ai_interface& ai_obj = get_active_ai_for_side(side);
|
||||
ai_obj.user_interact().attach_handler(event_observer);
|
||||
ai_obj.unit_recruited().attach_handler(event_observer);
|
||||
ai_obj.unit_moved().attach_handler(event_observer);
|
||||
ai_obj.enemy_attacked().attach_handler(event_observer);
|
||||
ai_obj.play_turn();
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ public:
|
||||
* doesn't occur too often, so there is no problem with calling it very
|
||||
* regularly.
|
||||
*/
|
||||
static void raise_unit_interact();
|
||||
static void raise_user_interact();
|
||||
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user