MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / LockPosition

Method LockPosition

engine/Poseidon/AI/AIUnit.cpp:126–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126void AILocker::LockPosition(Vector3Val pos, float radius, bool soldier, float size)
127{
128 int LockRange = toIntCeil(radius * InvOperItemGrid);
129 if (LockRange < 0)
130 {
131 LockRange = 0;
132 }
133
134 int xx, x = toIntFloor(pos.X() * InvOperItemGrid);
135 int zz, z = toIntFloor(pos.Z() * InvOperItemGrid);
136 for (xx = -LockRange; xx <= LockRange; xx++)
137 {
138 for (zz = -LockRange; zz <= LockRange; zz++)
139 {
140 float xr = (x + xx + 0.5f) * OperItemGrid - pos.X();
141 float zr = (z + zz + 0.5f) * OperItemGrid - pos.Z();
142 if (xr * xr + zr * zr < radius * radius || xx == 0 && zz == 0)
143 {
144 LockItem(x + xx, z + zz, true);
145 }
146 }
147 }
148
149 AI_ERROR(GRoadNet);
150 x = toIntFloor(pos.X() * InvLandGrid);
151 z = toIntFloor(pos.Z() * InvLandGrid);
152 // lock road item if vehicle is inside "boundingSphere" + size
153 for (zz = z - 1; zz <= z + 1; zz++)
154 {
155 for (xx = x - 1; xx <= x + 1; xx++)
156 {
157 if (!InRange(xx, zz))
158 {
159 continue;
160 }
161 RoadList& roadList = GRoadNet->GetRoadList(xx, zz);
162 int i;
163 for (i = 0; i < roadList.Size(); i++)
164 {
165 RoadLink* item = roadList[i];
166 if (item->IsInside(pos, size))
167 {
168 item->Lock();
169 _roads.Add(item);
170 }
171 }
172 }
173 }
174
175 if (soldier)
176 {
177 // this is not clear - pos is AimingPosition, we need position on surface
178 Vector3 realPos = pos - Vector3(0, 1, 0);
179
180 // lock position in house
181 int xMin, xMax, zMin, zMax;
182 ObjRadiusRectangle(xMin, xMax, zMin, zMax, pos, pos, 50);
183 for (int x = xMin; x <= xMax; x++)

Callers

nothing calls this directly

Calls 15

LockItemClass · 0.85
ObjRadiusRectangleFunction · 0.85
Vector3Class · 0.50
SquareFunction · 0.50
XMethod · 0.45
ZMethod · 0.45
SizeMethod · 0.45
IsInsideMethod · 0.45
LockMethod · 0.45
AddMethod · 0.45
GetIPathsMethod · 0.45
NPosMethod · 0.45

Tested by

no test coverage detected