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 <landscapemap/TargetGroupsGroupEntry.h>
22 #include <landscapemap/HeightMap.h>
23 #include <common/Defines.h>
24 #include <common/Vector.h>
26 TargetGroupsGroupEntry::TargetGroupsGroupEntry(
27 const char *name
, HeightMap
&map
) :
28 TargetGroupsSetEntry(name
),
33 mapWidth_
= map
.getMapWidth() / mapWidthMult_
;
34 mapHeight_
= map
.getMapHeight() / mapHeightMult_
;
36 distance_
= new float[mapWidth_
* mapHeight_
];
37 for (int a
=0; a
<mapWidth_
; a
++)
39 for (int b
=0; b
<mapHeight_
; b
++)
41 distance_
[a
+ b
* mapWidth_
] = 255.0f
;
46 TargetGroupsGroupEntry::~TargetGroupsGroupEntry()
51 float TargetGroupsGroupEntry::getDistance(int x
, int y
)
56 if (x
>=0 && x
< mapWidth_
&& y
>=0 && y
< mapHeight_
)
58 return distance_
[x
+ y
* mapWidth_
];
63 void TargetGroupsGroupEntry::addObject(TargetGroup
*object
, bool thin
)
65 TargetGroupsSetEntry::addObject(object
, thin
);
67 static unsigned int objectCount
= 0;
68 if (thin
&& objectCount
++ % 3 != 0) return;
70 int x
= object
->getPosition()[0].asInt();
71 int y
= object
->getPosition()[1].asInt();
76 if (x
>=0 && x
< mapWidth_
&& y
>=0 && y
< mapHeight_
)
79 for (int a
=0; a
<mapWidth_
; a
++)
81 for (int b
=0; b
<mapHeight_
; b
++)
85 float d
= posB
.Magnitude();
86 distance_
[a
+ b
* mapWidth_
] = MIN(distance_
[a
+ b
* mapWidth_
], d
);
92 bool TargetGroupsGroupEntry::removeObject(TargetGroup
*object
)
94 int x
= object
->getPosition()[0].asInt();
95 int y
= object
->getPosition()[1].asInt();
99 if (x
>=0 && x
< mapWidth_
&& y
>=0 && y
< mapHeight_
)
101 distance_
[x
+ y
* mapWidth_
] += 2.0f
;
104 return TargetGroupsSetEntry::removeObject(object
);