TankAIStrings.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <tankai/TankAIStrings.h>
00022 #include <common/Defines.h>
00023 #include <common/OptionsScorched.h>
00024 #include <engine/ActionController.h>
00025 
00026 TankAIStrings *TankAIStrings::instance_ = 0;
00027 
00028 TankAIStrings *TankAIStrings::instance()
00029 {
00030         if (!instance_)
00031         {
00032                 instance_ = new TankAIStrings;
00033         }
00034 
00035         return instance_;
00036 }
00037 
00038 TankAIStrings::TankAIStrings()
00039 {
00040         // Check we have init correctly
00041         bool s1 = deathLines_.readFile(S3D::getDataFile("data/talk/talk2.txt"));
00042         bool s2 = attackLines_.readFile(S3D::getDataFile("data/talk/talk1.txt"));
00043         bool s3 = aiPlayerNames_.readFile(S3D::getDataFile("data/ainames.txt"));
00044         bool s4 = playerNames_.readFile(S3D::getDataFile("data/playernames.txt"));
00045         DIALOG_ASSERT(s1 && s2 && s3 && s4);
00046 }
00047 
00048 TankAIStrings::~TankAIStrings()
00049 {
00050 }
00051 
00052 const char *TankAIStrings::getPlayerName()
00053 {
00054         static unsigned int counter = 0;
00055         const char *playerName = 
00056                 playerNames_.getLines()[counter++ % playerNames_.getLines().size()].c_str();
00057         return playerName;
00058 }
00059 
00060 const char *TankAIStrings::getAIPlayerName(ScorchedContext &context)
00061 {
00062         static unsigned int counter = 0;
00063         if (context.getOptionsGame().getRandomizeBotNames())
00064         {
00065                 counter = (int) rand();
00066         }
00067 
00068         const char *playerName = 
00069                 aiPlayerNames_.getLines()[counter++ % aiPlayerNames_.getLines().size()].c_str();
00070         return playerName;
00071 }
00072 
00073 const char *TankAIStrings::getDeathLine(ScorchedContext &context)
00074 {
00075         RandomGenerator &generator = context.getActionController().getRandom();
00076         const char *deathLine = 0;
00077         fixed percentage = 
00078                 fixed(context.getOptionsGame().getComputersDeathTalk());
00079         fixed talkPer = generator.getRandFixed() * 100;
00080         if (talkPer < percentage)
00081         {
00082                 deathLine = deathLines_.getLines()
00083                         [generator.getRandUInt() % deathLines_.getLines().size()].c_str();
00084         }
00085 
00086         return deathLine;
00087 }
00088 
00089 const char *TankAIStrings::getAttackLine(ScorchedContext &context)
00090 {
00091         RandomGenerator &generator = context.getActionController().getRandom();
00092         const char *attackLine = 0;
00093         fixed percentage = 
00094                 fixed(context.getOptionsGame().getComputersAttackTalk());
00095         fixed talkPer = generator.getRandFixed() * 100;
00096         if (talkPer < percentage)
00097         {
00098                 attackLine = attackLines_.getLines()
00099                         [generator.getRandUInt() % attackLines_.getLines().size()].c_str();
00100         }
00101         
00102         return attackLine;
00103 }

Generated on Mon Feb 16 15:14:53 2009 for Scorched3D by  doxygen 1.5.3