1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <XML/XMLFile.h>
22 #include <common/Defines.h>
23 #include <tankai/TankAIStore.h>
24 #include <tankai/TankAICurrent.h>
25 #include <tankai/TankAIShallow.h>
26 #include <tankai/TankAIRandom.h>
29 TankAIStore::TankAIStore()
34 TankAIStore::~TankAIStore()
39 void TankAIStore::clearAIs()
43 TankAI
*ai
= ais_
.front();
49 bool TankAIStore::loadAIs(bool shallow
)
51 // Load key definition file
53 if (!file
.readFile(S3D::getDataFile("data/tankais.xml")))
55 S3D::dialogMessage("TankAIStore",
56 S3D::formatStringBuffer("Failed to parse \"%s\"\n%s",
58 file
.getParserError()));
63 if (!file
.getRootNode())
65 S3D::dialogMessage("TankAIStore",
66 S3D::formatStringBuffer("Failed to find tank ai definition file \"%s\"",
71 // Itterate all of the keys in the file
72 std::list
<XMLNode
*>::iterator childrenItor
;
73 std::list
<XMLNode
*> &children
= file
.getRootNode()->getChildren();
74 for (childrenItor
= children
.begin();
75 childrenItor
!= children
.end();
79 XMLNode
*currentNode
= (*childrenItor
);
80 if (strcmp(currentNode
->getName(), "ai"))
82 S3D::dialogMessage("TankAIStore",
83 "Failed to find ai node");
88 if (shallow
) computer
= new TankAIShallow
;
89 else computer
= new TankAICurrent
;
90 if (!computer
->parseConfig(currentNode
))
98 // Add the random player
100 TankAIRandom
*tankAI
= new TankAIRandom
;
101 bool foundRandom
= false;
102 std::list
<TankAI
*>::iterator itor
;
103 for (itor
= ais_
.begin();
107 TankAI
*ai
= (*itor
);
108 if (ai
->availableForRandom())
111 tankAI
->addTankAI(ai
);
116 S3D::dialogMessage("TankAIStore",
117 "No tank ais are marked availableforrandom");
127 TankAI
*TankAIStore::getAIByName(const char *name
)
130 std::list
<TankAI
*>::iterator itor
;
131 for (itor
= ais_
.begin();
135 if (!strcmp((*itor
)->getName(), name
)) return (*itor
);
141 void TankAIStore::addAI(TankAI
*ai
)