1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
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.
10 //
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.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include <placement/PlacementTypeDirect.h>
22 #include <landscapemap/LandscapeMaps.h>
23 #include <engine/ScorchedContext.h>
24 #include <common/ProgressCounter.h>
25 #include <XML/XMLParser.h>
26 
PlacementTypeDirect()27 PlacementTypeDirect::PlacementTypeDirect()
28 {
29 }
30 
~PlacementTypeDirect()31 PlacementTypeDirect::~PlacementTypeDirect()
32 {
33 }
34 
readXML(XMLNode * node)35 bool PlacementTypeDirect::readXML(XMLNode *node)
36 {
37 	XMLNode *positionNode;
38 	while (node->getNamedChild("position", positionNode, false))
39 	{
40 		Position position;
41 		if (!positionNode->getNamedChild("position", position.position)) return false;
42 		positions.push_back(position);
43 
44 		if (!positionNode->failChildren()) return false;
45 	}
46 	return PlacementType::readXML(node);
47 }
48 
getPositions(ScorchedContext & context,RandomGenerator & generator,std::list<Position> & returnPositions,ProgressCounter * counter)49 void PlacementTypeDirect::getPositions(ScorchedContext &context,
50 	RandomGenerator &generator,
51 	std::list<Position> &returnPositions,
52 	ProgressCounter *counter)
53 {
54 	std::list<Position>::iterator itor;
55 	int i = 0;
56 	for (itor = positions.begin();
57 		itor != positions.end();
58 		++itor, i++)
59 	{
60 		if (i % 10 == 0) if (counter)
61 			counter->setNewPercentage(float(i)/float(positions.size())*100.0f);
62 
63 		Position position = (*itor);
64 		fixed height =
65 			context.getLandscapeMaps().
66 				getGroundMaps().getInterpHeight(position.position[0], position.position[1]);
67 		if (position.position[2] == 0) position.position[2] = height;
68 
69 		returnPositions.push_back(position);
70 	}
71 }
72