git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / target / TargetGroup.cpp
blob9e44f1a59ef39f62d41992ef95aa7573cd38a990
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
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.
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 <target/TargetGroup.h>
22 #include <target/Target.h>
23 #include <target/TargetLife.h>
24 #include <engine/ScorchedContext.h>
25 #include <landscapemap/TargetGroupsGroupEntry.h>
26 #include <landscapemap/LandscapeMaps.h>
27 #include <net/NetBuffer.h>
28 #include <set>
30 TargetGroup::TargetGroup(ScorchedContext &context) :
31 context_(context)
35 TargetGroup::~TargetGroup()
39 FixedVector &TargetGroup::getPosition()
41 return target_->getLife().getTargetPosition();
44 bool TargetGroup::writeMessage(NetBuffer &buffer)
46 std::set<std::string> names;
47 std::vector<TargetGroupsGroupEntry *>::iterator itor;
48 for (itor = groups.begin();
49 itor != groups.end();
50 itor++)
52 TargetGroupsGroupEntry *group = *itor;
53 names.insert(group->getName());
55 buffer.addToBuffer((int) names.size());
56 std::set<std::string>::iterator itor2;
57 for (itor2 = names.begin();
58 itor2 != names.end();
59 itor2++)
61 std::string name = *itor2;
62 buffer.addToBuffer(name);
65 return true;
68 bool TargetGroup::readMessage(NetBufferReader &reader)
70 int groupNo = 0;
71 if (!reader.getFromBuffer(groupNo)) return false;
72 for (int g=0; g<groupNo; g++)
74 std::string groupName;
75 if (!reader.getFromBuffer(groupName)) return false;
77 TargetGroupsGroupEntry *group =
78 context_.getLandscapeMaps().getGroundMaps().getGroups().getGroup(groupName.c_str());
79 if (group && !group->hasObject(this))
81 group->addObject(this, false);
85 return true;