Applied a (slightly modified) version of jskij7's patch to create

an AI that actively collects items. This is (for now) the new default
AI - feedback welcome!


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11291 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2012-06-10 19:52:11 +00:00
parent 34b0fa1056
commit e7b0874274
7 changed files with 1454 additions and 21 deletions

View File

@ -94,14 +94,15 @@ src/items/projectile_manager.cpp
src/items/rubber_ball.cpp
src/items/rubber_band.cpp
src/items/swatter.cpp
src/karts/abstract_kart.cpp
src/karts/abstract_kart_animation.cpp
src/karts/abstract_kart.cpp
src/karts/cannon_animation.cpp
src/karts/controller/ai_base_controller.cpp
src/karts/controller/controller.cpp
src/karts/controller/default_ai_controller.cpp
src/karts/controller/end_controller.cpp
src/karts/controller/player_controller.cpp
src/karts/controller/present_ai.cpp
src/karts/controller/skidding_ai.cpp
src/karts/explosion_animation.cpp
src/karts/ghost_kart.cpp
@ -184,13 +185,13 @@ src/states_screens/kart_selection.cpp
src/states_screens/main_menu_screen.cpp
src/states_screens/minimal_race_gui.cpp
src/states_screens/options_screen_audio.cpp
src/states_screens/options_screen_input.cpp
src/states_screens/options_screen_input2.cpp
src/states_screens/options_screen_input.cpp
src/states_screens/options_screen_players.cpp
src/states_screens/options_screen_ui.cpp
src/states_screens/options_screen_video.cpp
src/states_screens/race_gui.cpp
src/states_screens/race_gui_base.cpp
src/states_screens/race_gui.cpp
src/states_screens/race_gui_overworld.cpp
src/states_screens/race_result_gui.cpp
src/states_screens/race_setup_screen.cpp
@ -251,8 +252,8 @@ src/animations/billboard_animation.hpp
src/animations/ipo.hpp
src/animations/three_d_animation.hpp
src/audio/dummy_sfx.hpp
src/audio/music.hpp
src/audio/music_dummy.hpp
src/audio/music.hpp
src/audio/music_information.hpp
src/audio/music_manager.hpp
src/audio/music_ogg.hpp
@ -260,8 +261,8 @@ src/audio/sfx_base.hpp
src/audio/sfx_buffer.hpp
src/audio/sfx_manager.hpp
src/audio/sfx_openal.hpp
src/challenges/challenge.hpp
src/challenges/challenge_data.hpp
src/challenges/challenge.hpp
src/challenges/game_slot.hpp
src/challenges/unlock_manager.hpp
src/config/device_config.hpp
@ -302,11 +303,11 @@ src/guiengine/scalable_font.hpp
src/guiengine/screen.hpp
src/guiengine/skin.hpp
src/guiengine/widget.hpp
src/guiengine/widgets.hpp
src/guiengine/widgets/bubble_widget.hpp
src/guiengine/widgets/button_widget.hpp
src/guiengine/widgets/check_box_widget.hpp
src/guiengine/widgets/dynamic_ribbon_widget.hpp
src/guiengine/widgets.hpp
src/guiengine/widgets/icon_button_widget.hpp
src/guiengine/widgets/label_widget.hpp
src/guiengine/widgets/list_widget.hpp
@ -317,8 +318,8 @@ src/guiengine/widgets/spinner_widget.hpp
src/guiengine/widgets/text_box_widget.hpp
src/input/binding.hpp
src/input/device_manager.hpp
src/input/input.hpp
src/input/input_device.hpp
src/input/input.hpp
src/input/input_manager.hpp
src/input/wiimote_manager.hpp
src/io/file_manager.hpp
@ -339,8 +340,8 @@ src/items/projectile_manager.hpp
src/items/rubber_ball.hpp
src/items/rubber_band.hpp
src/items/swatter.hpp
src/karts/abstract_kart.hpp
src/karts/abstract_kart_animation.hpp
src/karts/abstract_kart.hpp
src/karts/cannon_animation.hpp
src/karts/controller/ai_base_controller.hpp
src/karts/controller/controller.hpp
@ -348,11 +349,12 @@ src/karts/controller/default_ai_controller.hpp
src/karts/controller/end_controller.hpp
src/karts/controller/kart_control.hpp
src/karts/controller/player_controller.hpp
src/karts/controller/present_ai.hpp
src/karts/controller/skidding_ai.hpp
src/karts/explosion_animation.hpp
src/karts/ghost_kart.hpp
src/karts/kart.hpp
src/karts/kart_gfx.hpp
src/karts/kart.hpp
src/karts/kart_model.hpp
src/karts/kart_properties.hpp
src/karts/kart_properties_manager.hpp
@ -442,13 +444,13 @@ src/states_screens/kart_selection.hpp
src/states_screens/main_menu_screen.hpp
src/states_screens/minimal_race_gui.hpp
src/states_screens/options_screen_audio.hpp
src/states_screens/options_screen_input.hpp
src/states_screens/options_screen_input2.hpp
src/states_screens/options_screen_input.hpp
src/states_screens/options_screen_players.hpp
src/states_screens/options_screen_ui.hpp
src/states_screens/options_screen_video.hpp
src/states_screens/race_gui.hpp
src/states_screens/race_gui_base.hpp
src/states_screens/race_gui.hpp
src/states_screens/race_gui_overworld.hpp
src/states_screens/race_result_gui.hpp
src/states_screens/race_setup_screen.hpp
@ -477,8 +479,8 @@ src/tracks/check_sphere.hpp
src/tracks/check_structure.hpp
src/tracks/graph_node.hpp
src/tracks/lod_node_loader.hpp
src/tracks/quad.hpp
src/tracks/quad_graph.hpp
src/tracks/quad.hpp
src/tracks/quad_set.hpp
src/tracks/terrain_info.hpp
src/tracks/track.hpp
@ -486,8 +488,8 @@ src/tracks/track_manager.hpp
src/tracks/track_object.hpp
src/tracks/track_object_manager.hpp
src/tracks/track_sector.hpp
src/tutorial/tutorial.hpp
src/tutorial/tutorial_data.hpp
src/tutorial/tutorial.hpp
src/tutorial/tutorial_manager.hpp
src/utils/aligned_array.hpp
src/utils/constants.hpp

View File

@ -923,6 +923,10 @@
RelativePath="..\..\karts\controller\player_controller.cpp"
>
</File>
<File
RelativePath="..\..\karts\controller\present_ai.cpp"
>
</File>
<File
RelativePath="..\..\karts\controller\skidding_ai.cpp"
>
@ -2074,6 +2078,10 @@
RelativePath="..\..\karts\moveable.hpp"
>
</File>
<File
RelativePath="..\..\karts\controller\present_ai.hpp"
>
</File>
<File
RelativePath="..\..\karts\rescue_animation.hpp"
>

View File

@ -147,6 +147,10 @@ public:
virtual ~Item ();
void update (float delta);
virtual void collected(const AbstractKart *kart, float t=2.0f);
void setParent(AbstractKart* parent);
void reset();
void switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh);
void switchBack();
// ------------------------------------------------------------------------
/** Returns true if the Kart is close enough to hit this item, the item is
@ -192,10 +196,8 @@ public:
/** Returns the time the item is disabled for. */
float getDisableTime() const { return m_time_till_return; }
// ------------------------------------------------------------------------
void setParent(AbstractKart* parent);
void reset();
void switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh);
void switchBack();
/** Returns the XYZ position of the item. */
const Vec3& getXYZ() const { return m_xyz; }
}; // class Item
#endif

View File

@ -76,9 +76,16 @@ public:
int add_info=-1);
void switchItems ();
void setSwitchItems(const std::vector<int> &switch_items);
// ------------------------------------------------------------------------
scene::IMesh* getItemModel (Item::ItemType type)
{return m_item_mesh[type];}
};
// ------------------------------------------------------------------------
/** Returns the number of items. */
unsigned int getNumberOfItems() const { return m_all_items.size(); }
// ------------------------------------------------------------------------
/** Returns a pointer to the n-th item. */
const Item * getItem(unsigned int n) const { return m_all_items[n]; };
}; // ItemManager
extern ItemManager* item_manager;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,314 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
// Copyright (C) 2006-2007 Eduardo Hernandez Munoz
// Copyright (C) 2010 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PRESENT_AI_HPP
#define HEADER_PRESENT_AI_HPP
#include "karts/controller/ai_base_controller.hpp"
class Track;
class LinearWorld;
class QuadGraph;
namespace irr
{
namespace scene
{
class ISceneNode;
}
}
/**
* \ingroup controller
*/
class PresentAI : public AIBaseController
{
private:
/** How the AI uses nitro. */
enum {NITRO_NONE, NITRO_SOME, NITRO_ALL} m_nitro_level;
enum ItemTactic
{
IT_TEN_SECONDS, //Fire after 10 seconds have passed, since the item
//was grabbed.
IT_CALCULATE //Aim carefully, check for enough space for boosters,
//and that other conditions are meet before firing.
};
class CrashTypes
{
public:
bool m_road; //true if we are going to 'crash' with the bounds of the road
int m_kart; //-1 if no crash, pos numbers are the kart it crashes with
CrashTypes() : m_road(false), m_kart(-1) {};
void clear() {m_road = false; m_kart = -1;}
} m_crashes;
/*Difficulty handling variables*/
/** Chance of a false start. */
float m_false_start_probability;
/** The minimum delay time before a AI kart starts. */
float m_min_start_delay;
/** The maximum delay time before an AI kart starts. */
float m_max_start_delay;
/** The actual start delay used. */
float m_start_delay;
/** Minimum number of steps to check. If 0, the AI doesn't even has check
* around the kart, if 1, it checks around the kart always, and more
* than that will check the remaining number of steps in front of the
* kart, always. */
int m_min_steps;
/** If true, the acceleration is decreased when the AI is in a better
* position than all the human players. */
bool m_wait_for_players;
/** The allowed maximum speed in percent of the kart's maximum speed. */
float m_max_handicap_speed;
/** How are items going to be used? */
ItemTactic m_item_tactic;
/** True if the kart should try to pass on a bomb to another kart. */
bool m_handle_bomb;
/** True if the AI should avtively try to make use of slipstream. */
bool m_make_use_of_slipstream;
/*General purpose variables*/
/** Pointer to the closest kart ahead of this kart. NULL if this
* kart is first. */
AbstractKart *m_kart_ahead;
/** Distance to the kart ahead. */
float m_distance_ahead;
/** Pointer to the closest kart behind this kart. NULL if this kart
* is last. */
AbstractKart *m_kart_behind;
/** Distance to the kard behind. */
float m_distance_behind;
/** Time an item has been collected and not used. */
float m_time_since_last_shot;
float m_curve_target_speed;
float m_curve_angle;
float m_time_since_stuck;
int m_start_kart_crash_direction; //-1 = left, 1 = right, 0 = no crash.
/** For debugging purpose: a sphere indicating where the AI
* is targeting at. */
irr::scene::ISceneNode *m_debug_sphere;
/*Functions called directly from update(). They all represent an action
*that can be done, and end up setting their respective m_controls
*variable, except handle_race_start() that isn't associated with any
*specific action (more like, associated with inaction).
*/
void handleRaceStart();
void handleAcceleration(const float dt);
void handleSteering(float dt);
void handleItems(const float dt);
void handleRescue(const float dt);
void handleBraking();
void handleNitroAndZipper();
void computeNearestKarts();
void checkCrashes(int steps, const Vec3& pos);
void findNonCrashingPoint(Vec3 *result);
int calcSteps();
void findCurve();
protected:
virtual unsigned int getNextSector(unsigned int index);
public:
PresentAI(AbstractKart *kart);
~PresentAI();
virtual void update (float delta);
virtual void reset ();
}; // PresentAI
#endif
/* EOF */
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
// Copyright (C) 2006-2007 Eduardo Hernandez Munoz
// Copyright (C) 2010 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PRESENT_AI_HPP
#define HEADER_PRESENT_AI_HPP
#include "karts/controller/ai_base_controller.hpp"
class Track;
class LinearWorld;
class QuadGraph;
namespace irr
{
namespace scene
{
class ISceneNode;
}
}
/**
* \ingroup controller
*/
class PresentAI : public AIBaseController
{
private:
/** How the AI uses nitro. */
enum {NITRO_NONE, NITRO_SOME, NITRO_ALL} m_nitro_level;
enum ItemTactic
{
IT_TEN_SECONDS, //Fire after 10 seconds have passed, since the item
//was grabbed.
IT_CALCULATE //Aim carefully, check for enough space for boosters,
//and that other conditions are meet before firing.
};
class CrashTypes
{
public:
bool m_road; //true if we are going to 'crash' with the bounds of the road
int m_kart; //-1 if no crash, pos numbers are the kart it crashes with
CrashTypes() : m_road(false), m_kart(-1) {};
void clear() {m_road = false; m_kart = -1;}
} m_crashes;
/*Difficulty handling variables*/
/** Chance of a false start. */
float m_false_start_probability;
/** The minimum delay time before a AI kart starts. */
float m_min_start_delay;
/** The maximum delay time before an AI kart starts. */
float m_max_start_delay;
/** The actual start delay used. */
float m_start_delay;
/** Minimum number of steps to check. If 0, the AI doesn't even has check
* around the kart, if 1, it checks around the kart always, and more
* than that will check the remaining number of steps in front of the
* kart, always. */
int m_min_steps;
/** If true, the acceleration is decreased when the AI is in a better
* position than all the human players. */
bool m_wait_for_players;
/** The allowed maximum speed in percent of the kart's maximum speed. */
float m_max_handicap_speed;
/** How are items going to be used? */
ItemTactic m_item_tactic;
/** True if the kart should try to pass on a bomb to another kart. */
bool m_handle_bomb;
/** True if the AI should avtively try to make use of slipstream. */
bool m_make_use_of_slipstream;
/*General purpose variables*/
/** Pointer to the closest kart ahead of this kart. NULL if this
* kart is first. */
AbstractKart *m_kart_ahead;
/** Distance to the kart ahead. */
float m_distance_ahead;
/** Pointer to the closest kart behind this kart. NULL if this kart
* is last. */
AbstractKart *m_kart_behind;
/** Distance to the kard behind. */
float m_distance_behind;
/** Time an item has been collected and not used. */
float m_time_since_last_shot;
float m_curve_target_speed;
float m_curve_angle;
float m_time_since_stuck;
int m_start_kart_crash_direction; //-1 = left, 1 = right, 0 = no crash.
/** For debugging purpose: a sphere indicating where the AI
* is targeting at. */
irr::scene::ISceneNode *m_debug_sphere;
/*Functions called directly from update(). They all represent an action
*that can be done, and end up setting their respective m_controls
*variable, except handle_race_start() that isn't associated with any
*specific action (more like, associated with inaction).
*/
void handleRaceStart();
void handleAcceleration(const float dt);
void handleSteering(float dt);
void handleItems(const float dt);
void handleRescue(const float dt);
void handleBraking();
void handleNitroAndZipper();
void computeNearestKarts();
void checkCrashes(int steps, const Vec3& pos);
void findNonCrashingPoint(Vec3 *result);
int calcSteps();
void findCurve();
protected:
virtual unsigned int getNextSector(unsigned int index);
public:
PresentAI(AbstractKart *kart);
~PresentAI();
virtual void update (float delta) ;
virtual void reset ();
};
#endif
/* EOF */

View File

@ -37,6 +37,7 @@
#include "karts/controller/player_controller.hpp"
#include "karts/controller/end_controller.hpp"
#include "karts/controller/skidding_ai.hpp"
#include "karts/controller/present_ai.hpp"
#include "karts/kart.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/profile_world.hpp"
@ -243,11 +244,11 @@ Controller* World::loadAIController(AbstractKart *kart)
// const int NUM_ROBOTS = 1;
// For now: instead of random switching, use each
// robot in turns: switch(m_random.get(NUM_ROBOTS))
// static int turn=1;
// turn=1-turn;
//static int turn=0;
//turn=2-turn;
// For now disable the new AI.
int turn=0;
int turn=2;
switch(turn)
{
case 0:
@ -256,6 +257,9 @@ Controller* World::loadAIController(AbstractKart *kart)
case 1:
controller = new SkiddingAI(kart);
break;
case 2:
controller = new PresentAI(kart);
break;
default:
fprintf(stderr, "Warning: Unknown robot, using default.\n");
controller = new DefaultAIController(kart);