Skip to content
Permalink
Browse files

fix #6215

  • Loading branch information...
rt
rt committed May 2, 2019
1 parent 7b5b798 commit 41b4b2c5950f78b3aba1e9eda40da1f493132315
Showing with 32 additions and 39 deletions.
  1. +4 −5 rts/Lua/LuaSyncedCtrl.cpp
  2. +12 −14 rts/Sim/Objects/SolidObject.cpp
  3. +2 −0 rts/Sim/Objects/SolidObject.h
  4. +14 −20 rts/Sim/Units/UnitTypes/Factory.cpp
@@ -528,12 +528,11 @@ static int SetSolidObjectRotation(lua_State* L, CSolidObject* o, bool isFeature)

o->SetDirVectorsEuler(float3(luaL_checkfloat(L, 2), luaL_checkfloat(L, 3), luaL_checkfloat(L, 4)));

if (isFeature) {
// not a hack: ForcedSpin() and CalculateTransform() calculate a
// transform based only on frontdir and assume the helper y-axis
// points up
// not a hack: ForcedSpin() and CalculateTransform() calculate a
// transform based only on frontdir and assume the helper y-axis
// points up
if (isFeature)
static_cast<CFeature*>(o)->UpdateTransform(o->pos, true);
}

return 0;
}
@@ -343,24 +343,23 @@ float3 CSolidObject::GetWantedUpDir(bool useGroundNormal) const
const float3 gn = CGround::GetSmoothNormal(pos.x, pos.z) * ( useGroundNormal);
const float3 wn = UpVector * (1 - useGroundNormal);

if (moveDef == nullptr) {
// aircraft cannot use updir reliably or their
// coordinate-system would degenerate too much
// over time without periodic re-ortho'ing
// aircraft cannot use updir reliably or their
// coordinate-system would degenerate too much
// over time without periodic re-ortho'ing
if (moveDef == nullptr)
return (gn + UpVector * (1 - useGroundNormal));
}

// not an aircraft if we get here, prevent pitch changes
// if(f) the object is neither on the ground nor in water
// for whatever reason (GMT also prevents heading changes)
if (!IsInAir()) {
switch (moveDef->speedModClass) {
case MoveDef::Tank: { return ((gn + wn) * IsOnGround() + updir * (1 - IsOnGround())); } break;
case MoveDef::KBot: { return ((gn + wn) * IsOnGround() + updir * (1 - IsOnGround())); } break;
case MoveDef::Tank: { return mix(float3(updir), gn + wn, IsOnGround()); } break;
case MoveDef::KBot: { return mix(float3(updir), gn + wn, IsOnGround()); } break;

case MoveDef::Hover: { return ((UpVector * IsInWater()) + (gn + wn) * (1 - IsInWater())); } break;
case MoveDef::Ship : { return ((UpVector * IsInWater()) + (gn + wn) * (1 - IsInWater())); } break;
default : { } break;
case MoveDef::Hover: { return mix(UpVector, gn + wn, 1 - IsInWater()); } break;
case MoveDef::Ship : { return mix(UpVector, gn + wn, 1 - IsInWater()); } break;
default : { } break;
}
}

@@ -378,13 +377,12 @@ void CSolidObject::SetDirVectorsEuler(const float3 angles)
// whenever these angles are retrieved, the handedness is converted again
SetDirVectors(matrix.RotateEulerXYZ(angles));
SetHeadingFromDirection();
SetFacingFromHeading();
UpdateMidAndAimPos();
}

void CSolidObject::SetHeadingFromDirection()
{
heading = GetHeadingFromVector(frontdir.x, frontdir.z);
}
void CSolidObject::SetHeadingFromDirection() { heading = GetHeadingFromVector(frontdir.x, frontdir.z); }
void CSolidObject::SetFacingFromHeading() { buildFacing = GetFacingFromHeading(heading); }

void CSolidObject::UpdateDirVectors(bool useGroundNormal)
{
@@ -152,6 +152,8 @@ class CSolidObject: public CWorldObject {
// update object's <heading> from current frontdir
// should always be called after a SetDirVectors()
void SetHeadingFromDirection();
// update object's <buildFacing> from current heading
void SetFacingFromHeading();
// update object's local coor-sys from current <heading>
// (unlike ForcedSpin which updates from given <updir>)
// NOTE: movetypes call this directly
@@ -379,14 +379,11 @@ void CFactory::SendToEmptySpot(CUnit* unit)
// (and should also be more than CMD_CANCEL_DIST
// elmos distant from foundPos)
//
if (!unit->unitDef->canfly && exitPos.IsInBounds()) {
Command c0(CMD_MOVE, SHIFT_KEY, exitPos);
unit->commandAI->GiveCommand(c0);
}
if (!unit->unitDef->canfly && exitPos.IsInBounds())
unit->commandAI->GiveCommand(Command(CMD_MOVE, SHIFT_KEY, exitPos));

// second actual empty-spot waypoint
Command c1(CMD_MOVE, SHIFT_KEY, foundPos);
unit->commandAI->GiveCommand(c1);
unit->commandAI->GiveCommand(Command(CMD_MOVE, SHIFT_KEY, foundPos));
}

void CFactory::AssignBuildeeOrders(CUnit* unit) {
@@ -410,22 +407,19 @@ void CFactory::AssignBuildeeOrders(CUnit* unit) {
// move-order. However, this order can *itself* cause the PF
// system to consider the path blocked if the extra waypoint
// falls within the factory's confines, so use a wide berth.
const float xs = unitDef->xsize * SQUARE_SIZE * 0.5f;
const float zs = unitDef->zsize * SQUARE_SIZE * 0.5f;
const float3 fpSize = {unitDef->xsize * SQUARE_SIZE * 0.5f, 0.0f, unitDef->zsize * SQUARE_SIZE * 0.5f};
const float3 fpMins = {unit->pos.x - fpSize.x, 0.0f, unit->pos.z - fpSize.z};
const float3 fpMaxs = {unit->pos.x + fpSize.x, 0.0f, unit->pos.z + fpSize.z};

float tmpDst = 2.0f;
float3 tmpPos = unit->pos + (frontdir * this->radius * tmpDst);
float3 tmpVec;
float3 tmpPos;

if (buildFacing == FACING_NORTH || buildFacing == FACING_SOUTH) {
while ((tmpPos.z >= unit->pos.z - zs) && (tmpPos.z <= unit->pos.z + zs)) {
tmpDst += 0.5f;
tmpPos = unit->pos + (frontdir * this->radius * tmpDst);
}
} else {
while ((tmpPos.x >= unit->pos.x - xs) && (tmpPos.x <= unit->pos.x + xs)) {
tmpDst += 0.5f;
tmpPos = unit->pos + (frontdir * this->radius * tmpDst);
}
for (int i = 0, k = 2 * (math::fabs(frontdir.z) > math::fabs(frontdir.x)); i < 128; i++) {
tmpVec = frontdir * radius * (2.0f + i * 0.5f);
tmpPos = unit->pos + tmpVec;

if ((tmpPos[k] < fpMins[k]) || (tmpPos[k] > fpMaxs[k]))
break;
}

c.PushPos(tmpPos.cClampInBounds());

0 comments on commit 41b4b2c

Please sign in to comment.
You can’t perform that action at this time.