Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ca_global_fallback.hpp"
00022
00023 #include "../composite/ai.hpp"
00024
00025 #include "../actions.hpp"
00026
00027 #include "../../game_display.hpp"
00028 #include "../../foreach.hpp"
00029 #include "../../log.hpp"
00030 #include "../../map.hpp"
00031 #include "../../map_label.hpp"
00032 #include "../../replay.hpp"
00033 #include "../../resources.hpp"
00034 #include "../../sdl_utils.hpp"
00035 #include "../../team.hpp"
00036 #include "../../terrain_filter.hpp"
00037 #include "../../tod_manager.hpp"
00038
00039
00040 namespace ai {
00041
00042 namespace testing_ai_default {
00043
00044 static lg::log_domain log_ai_testing_ca_global_fallback("ai/ca/global_fallback");
00045 #define DBG_AI LOG_STREAM(debug, log_ai_testing_ca_global_fallback)
00046 #define LOG_AI LOG_STREAM(info, log_ai_testing_ca_global_fallback)
00047 #define WRN_AI LOG_STREAM(warn, log_ai_testing_ca_global_fallback)
00048 #define ERR_AI LOG_STREAM(err, log_ai_testing_ca_global_fallback)
00049
00050
00051
00052
00053
00054 static void display_label(int , const map_location& location, const std::string& text, bool surrounded)
00055 {
00056 display* gui = display::get_singleton();
00057 std::string team_name;
00058
00059 SDL_Color color = int_to_color(team::get_side_rgb(surrounded ? 2 : 1 ) );
00060
00061 const terrain_label *res;
00062 res = gui->labels().set_label(location, text, team_name, color);
00063 if (res)
00064 recorder.add_label(res);
00065 }
00066
00067
00068
00069
00070 global_fallback_phase::global_fallback_phase( rca_context &context, const config &cfg )
00071 : candidate_action(context,cfg)
00072 {
00073 }
00074
00075
00076 global_fallback_phase::~global_fallback_phase()
00077 {
00078 }
00079
00080
00081 double global_fallback_phase::evaluate()
00082 {
00083 return get_score();
00084 }
00085
00086
00087 void global_fallback_phase::execute()
00088 {
00089 LOG_AI << "start" << std::endl;
00090 const int ticks = SDL_GetTicks();
00091 double res_sum = 0;
00092 foreach( unit &u, *resources::units)
00093 {
00094 if (u.side()!=get_side())
00095 {
00096 continue;
00097 }
00098 double res = 0.1;
00099 res_sum += res;
00100 display_label(get_side(),u.get_location(),str_cast(res),false);
00101 }
00102 LOG_AI << "sum is " << res_sum << std::endl;
00103
00104 LOG_AI << "end in [" << (SDL_GetTicks()-ticks) << "] ticks" << std::endl;
00105 }
00106
00107 }
00108
00109 }