1) Added new AI, which is not yet too different from the current one.

2) AIs can now modify the kart name, which is used in printing profile results, to
   include an AI identifiert.
3) NewAI and DefaultRobot are created un turns: first AI is DefaultRobot, then 
   NewAI, then Default...
4) Made specific mode in VS project file for irrlicht 1.6 (will be removed soon).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4213 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2009-11-08 12:19:33 +00:00
parent 6d89dd7ae0
commit dd02e0726f
10 changed files with 1621 additions and 23 deletions

View File

@@ -245,6 +245,8 @@ supertuxkart_SOURCES = \
replay/replay_recorder.hpp \
robots/default_robot.cpp \
robots/default_robot.hpp \
robots/new_ai.cpp \
robots/new_ai.hpp \
states_screens/challenges.cpp \
states_screens/challenges.hpp \
states_screens/credits.cpp \

View File

@@ -145,6 +145,70 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="irr1.6|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="2"
ManagedExtensions="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="..\..\bullet\src;&quot;$(STK_INCLUDE)&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;BT_NO_PROFILE;HAVE_GLUT"
MinimalRebuild="true"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
<AssemblyReference

View File

@@ -142,6 +142,70 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="irr1.6|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="../../enet/include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>

View File

@@ -184,6 +184,94 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="irr1.6|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="../../../src;../../../src/bullet/src;&quot;$(STK_INCLUDE)&quot;;../../../src/enet/include;&quot;C:\cygwin\home\jh235117\local\irrlicht-1.6\include&quot;"
PreprocessorDefinitions="BT_NO_PROFILE;HAVE_OPENAL;HAVE_OGGVORBIS;_DEBUG;_CONSOLE;WIN32;NOMINMAX;VERSION=\&quot;SVN\&quot;;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;DEBUG;PACKAGE=\&quot;supertuxkart\&quot;;HAVE_GETTEXT;ENABLE_NLS;HAVE_GLUT;HAVE_IRRLICHT;_CRTDBG_MAP_ALLOC;IRR_SVN"
GeneratePreprocessedFile="0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
FloatingPointExceptions="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib user32.lib gdi32.lib winmm.lib advapi32.lib OpenAL32.lib libogg.lib libvorbis.lib libvorbisfile.lib intl.lib Irrlicht.lib ws2_32.lib"
OutputFile="./../../../$(ProjectName)_d16.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(STK_LIB)&quot;;&quot;C:\cygwin\home\jh235117\local\irrlicht-1.6\lib\Win32-visualstudio&quot;"
IgnoreAllDefaultLibraries="false"
IgnoreDefaultLibraryNames="libcmt.lib"
GenerateDebugInformation="true"
GenerateMapFile="false"
MapFileName=""
MapExports="false"
SubSystem="1"
LinkTimeCodeGeneration="0"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
Profile="false"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
@@ -208,10 +296,6 @@
RelativePath="..\..\guiengine\abstract_state_manager.cpp"
>
</File>
<File
RelativePath="..\..\guiengine\cutscene.cpp"
>
</File>
<File
RelativePath="..\..\guiengine\engine.cpp"
>
@@ -224,10 +308,6 @@
RelativePath="..\..\guiengine\modaldialog.cpp"
>
</File>
<File
RelativePath="..\..\guiengine\my_button.cpp"
>
</File>
<File
RelativePath="..\..\guiengine\screen.cpp"
>
@@ -316,6 +396,10 @@
RelativePath="../../../src\robots\default_robot.cpp"
>
</File>
<File
RelativePath="..\..\robots\new_ai.cpp"
>
</File>
</Filter>
<Filter
Name="challenges"
@@ -792,6 +876,10 @@
<Filter
Name="states_screen"
>
<File
RelativePath="..\..\states_screens\challenges.cpp"
>
</File>
<File
RelativePath="..\..\states_screens\credits.cpp"
>
@@ -894,10 +982,6 @@
RelativePath="..\..\guiengine\abstract_state_manager.hpp"
>
</File>
<File
RelativePath="..\..\guiengine\cutscene.hpp"
>
</File>
<File
RelativePath="..\..\guiengine\engine.hpp"
>
@@ -910,10 +994,6 @@
RelativePath="..\..\guiengine\modaldialog.hpp"
>
</File>
<File
RelativePath="..\..\guiengine\my_button.hpp"
>
</File>
<File
RelativePath="..\..\guiengine\screen.hpp"
>
@@ -1002,6 +1082,10 @@
RelativePath="../../../src\robots\default_robot.hpp"
>
</File>
<File
RelativePath="..\..\robots\new_ai.hpp"
>
</File>
</Filter>
<Filter
Name="challenges"
@@ -1562,6 +1646,10 @@
<Filter
Name="states_screens"
>
<File
RelativePath="..\..\states_screens\challenges.hpp"
>
</File>
<File
RelativePath="..\..\states_screens\credits.hpp"
>

View File

@@ -21,17 +21,26 @@
#ifndef HEADER_AUTOKART_HPP
#define HEADER_AUTOKART_HPP
#include "irrlicht.h"
#include "karts/kart.hpp"
#include "karts/kart_properties.hpp"
class AutoKart : public Kart
{
public:
AutoKart(const std::string& kart_name, int position,
const btTransform& init_pos) :
Kart(kart_name, position, init_pos) {}
public:
AutoKart(const std::string& kart_name, int position,
const btTransform& init_pos) :
Kart(kart_name, position, init_pos) {}
bool isPlayerKart() const {return false;}
bool isPlayerKart() const {return false;}
virtual const irr::core::stringw& getName() const
{
// Static to avoid returning the address of a temporary
// string.
static irr::core::stringw name = Kart::getName()+"(auto)";
return name;
} // getName
};
#endif

View File

@@ -271,7 +271,7 @@ public:
void updatedWeight ();
void forceRescue ();
void handleExplosion (const Vec3& pos, bool direct_hit);
const irr::core::stringw& getName() const {return m_kart_properties->getName();}
virtual const irr::core::stringw& getName() const {return m_kart_properties->getName();}
const std::string& getIdent () const {return m_kart_properties->getIdent();}
virtual bool isPlayerKart () const {return false; }
// addMessages gets called by world to add messages to the gui

View File

@@ -45,6 +45,7 @@
#include "race/history.hpp"
#include "race/race_manager.hpp"
#include "robots/default_robot.hpp"
#include "robots/new_ai.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/constants.hpp"
@@ -188,11 +189,18 @@ Kart* World::loadRobot(const std::string& kart_name, int position,
const int NUM_ROBOTS = 1;
switch(m_random.get(NUM_ROBOTS))
// For now: instead of random switching, use each
// robot in turns: switch(m_random.get(NUM_ROBOTS))
static int turn=1;
turn=1-turn;
switch(turn)
{
case 0:
currentRobot = new DefaultRobot(kart_name, position, init_pos, m_track);
break;
case 1:
currentRobot = new NewAI(kart_name, position, init_pos, m_track);
break;
default:
std::cerr << "Warning: Unknown robot, using default." << std::endl;
currentRobot = new DefaultRobot(kart_name, position, init_pos, m_track);

View File

@@ -192,6 +192,12 @@ public:
void update (float delta) ;
void reset ();
virtual void crashed (Kart *k) {if(k) m_collided = true;};
virtual const irr::core::stringw& getName() const
{
// Static to avoid returning the address of a temporary string
static irr::core::stringw name=m_kart_properties->getName()+"(default)";
return name;
}
};
#endif

1151
src/robots/new_ai.cpp Executable file

File diff suppressed because it is too large Load Diff

206
src/robots/new_ai.hpp Normal file
View File

@@ -0,0 +1,206 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
// Copyright (C) 2006-2007 Eduardo Hernandez Munoz
//
// 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_NEWAI_HPP
#define HEADER_NEWAI_HPP
#include "karts/auto_kart.hpp"
#include "utils/vec3.hpp"
/* third coord won't be used */
class Track;
class LinearWorld;
class QuadGraph;
class irr::scene::ISceneNode;
class NewAI : public AutoKart
{
private:
enum FallbackTactic
{
FT_AVOID_TRACK_CRASH, //Only steer to avoid getting out of the road,
//otherwise, don't steer at all
FT_PARALLEL, //Stay parallel to the road
FT_FAREST_POINT //Drive towards the farest non-crashing point that
//the kart can drive to in a straight line without
//crashing with the track.
};
/** 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*/
float m_max_start_delay; //Delay before accelerating at the start of each
//race
int m_min_steps; //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
bool m_wait_for_players; //If true, the acceleration is decreased when
//the AI is in a better position than all the
//human players.
float m_max_handicap_accel; //The allowed maximum speed, in percentage,
//from 0.0 to 1.0. Used only when
//m_wait_for_players == true.
FallbackTactic m_fallback_tactic; //General steering procedure. Used
//mostly on straight lines and on curves
//that re too small to need special
//handling.
ItemTactic m_item_tactic; //How are items going to be used?
/** True if the kart should try to pass on a bomb to another kart. */
bool m_handle_bomb;
/*General purpose variables*/
//The crash percentage is how much of the time the AI has been crashing,
//if the AI has been crashing for some time, use the rescue.
float m_crash_time;
int m_collided; // true if the kart collided with the track
/** Pointer to the closest kart ahead of this kart. NULL if this
* kart is first. */
Kart *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. */
Kart *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_time_till_start; //Used to simulate a delay at the start of the
//race, since human players don't accelerate
//at the same time and rarely repeat the a
//previous timing.
float m_curve_target_speed;
float m_curve_angle;
/** Keep a pointer to the track to reduce calls */
Track *m_track;
/** Keep a pointer to world. */
LinearWorld *m_world;
/** The current node the kart is on. This can be different from the value
* in LinearWorld, since it takes the chosen path of the AI into account
* (e.g. the closest point in LinearWorld might be on a branch not
* chosen by the AI). */
int m_track_node;
/** The graph of qudas of this track. */
const QuadGraph *m_quad_graph;
/** Which of the successors of a node was selected by the AI. */
std::vector<int> m_successor_index;
/** For each node in the graph this list contains the chosen next node.
* For normal lap track without branches we always have
* m_next_node_index[i] = (i+1) % size;
* but if a branch is possible, the AI will select one option here.
* If the node is not used, m_next_node_index will be -1. */
std::vector<int> m_next_node_index;
/** For each graph node this list contains a list of the next X
* graph nodes. */
std::vector<std::vector<int> > m_all_look_aheads;
float m_time_since_stuck;
int m_start_kart_crash_direction; //-1 = left, 1 = right, 0 = no crash.
/** Length of the kart, storing it here saves many function calls. */
float m_kart_length;
/** Cache width of kart. */
float m_kart_width;
/** For debugging purpose: a sphere indicating where the AI
* is targeting at. */
irr::scene::ISceneNode *m_debug_sphere;
irr::scene::ISceneNode *m_debug_left, *m_debug_right;
/** The minimum steering angle at which the AI adds skidding. Lower values
* tend to improve the line the AI is driving. This is used to adjust for
* different AI levels.
*/
float m_skidding_threshold;
/*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 DELTA);
void handleSteering(float dt);
void handleItems(const float DELTA, const int STEPS);
void handleRescue(const float DELTA);
void handleBraking();
void handleNitroAndZipper();
void computeNearestKarts();
/*Lower level functions not called directly from update()*/
float steerToAngle(const size_t SECTOR, const float ANGLE);
float steerToPoint(const Vec3 &point, float dt);
void checkCrashes(const int STEPS, const Vec3& pos);
void findNonCrashingPoint(Vec3 *result);
float findNonCrashingAngle();
float normalizeAngle(float angle);
int calcSteps();
void setSteering(float angle, float dt);
void findCurve();
public:
NewAI(const std::string& kart_name, int position,
const btTransform& init_pos, const Track *track);
~NewAI();
void update (float delta) ;
void reset ();
virtual void crashed (Kart *k) {if(k) m_collided = true;};
virtual const irr::core::stringw& getName() const
{
static irr::core::stringw name = Kart::getName()+irr::core::stringw("(NewAI)");
return name;
} // getName
};
#endif
/* EOF */