00001 /****************************************************************************** 00002 * Wormux is a convivial mass murder game. 00003 * Copyright (C) 2001-2004 Lawrence Azzoug. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00018 ****************************************************************************** 00019 * Artificial intelligence stupid engine 00020 *****************************************************************************/ 00021 00022 #include "ai_engine_stupid.h" 00023 #include "../include/action_handler.h" 00024 #include "../character/body.h" 00025 #include "../character/move.h" 00026 #include "../interface/game_msg.h" 00027 #include "../map/map.h" 00028 #include "../network/randomsync.h" 00029 #include "../team/macro.h" 00030 #include "../team/teams_list.h" 00031 #include "../tool/error.h" 00032 #include "../tool/math_tools.h" 00033 #include "../tool/string_tools.h" 00034 00035 #include <iostream> 00036 00037 AIStupidEngine * AIStupidEngine::singleton = NULL; 00038 00039 AIStupidEngine::AIStupidEngine() 00040 { 00041 std::cout << "o Artificial Intelligence Stupid engine initialization" << std::endl; 00042 } 00043 00044 AIStupidEngine* AIStupidEngine::GetInstance() 00045 { 00046 if (singleton == NULL) 00047 singleton = new AIStupidEngine(); 00048 00049 return singleton; 00050 } 00051 00052 // -------------------------------------------------- 00053 00054 void AIStupidEngine::BeginTurn() 00055 { 00056 m_last_char = &ActiveCharacter(); 00057 m_enemy = NULL; 00058 00059 m_begin_turn_time = 0; 00060 m_step = 0; 00061 00062 m_movement.BeginTurn(); 00063 m_shoot.BeginTurn(); 00064 } 00065 00066 void AIStupidEngine::Refresh() 00067 { 00068 if (ActiveCharacter().IsDead()) 00069 return; 00070 00071 // new character to control 00072 if (&ActiveCharacter() != m_last_char) { 00073 BeginTurn(); 00074 } 00075 00076 // Get time 00077 uint local_time = Time::GetInstance()->ReadSec(); 00078 if (local_time != m_current_time) { 00079 m_current_time = local_time; 00080 } 00081 00082 // wait some seconds as if we are thinking... 00083 if (m_current_time < m_begin_turn_time + 3) 00084 return; 00085 00086 if (m_shoot.Refresh(m_current_time)) { 00087 m_movement.Move(m_current_time); 00088 } 00089 00090 // switch (m_step) 00091 // { 00092 // case 0: 00093 // if (m_nearest_enemy) { 00094 // // we already knows who to shoot 00095 // m_step = 1; 00096 // } else { 00097 // m_movement.Move(m_current_time); 00098 // } 00099 // break; 00100 // case 1: 00101 // // shoot !! 00102 // m_shoot.Shoot(m_current_time); 00103 // break; 00104 // case 2: 00105 // // go go go !! 00106 // ChooseDirection(); 00107 // m_step++; 00108 // break; 00109 // case 3: 00110 // m_movement.Move(m_current_time); 00111 // break; 00112 // case 4: 00113 // // Wait for end of turn 00114 // break; 00115 // default: 00116 // assert(false); 00117 // } 00118 00119 } 00120