2019-06-30 15:06:55 -04:00
|
|
|
#include "common.h"
|
2020-04-17 09:31:11 -04:00
|
|
|
|
2019-06-30 15:06:55 -04:00
|
|
|
#include "Bridge.h"
|
2019-07-04 07:04:34 -04:00
|
|
|
#include "Pools.h"
|
|
|
|
#include "ModelIndices.h"
|
|
|
|
#include "PathFind.h"
|
|
|
|
#include "Stats.h"
|
2019-06-30 15:06:55 -04:00
|
|
|
|
2020-04-16 15:19:56 -04:00
|
|
|
CEntity *CBridge::pLiftRoad;
|
|
|
|
CEntity *CBridge::pLiftPart;
|
|
|
|
CEntity *CBridge::pWeight;
|
2019-07-04 07:04:34 -04:00
|
|
|
|
2020-04-16 15:19:56 -04:00
|
|
|
int CBridge::State;
|
|
|
|
int CBridge::OldState;
|
2019-07-04 07:04:34 -04:00
|
|
|
|
2020-04-16 15:19:56 -04:00
|
|
|
float CBridge::DefaultZLiftPart;
|
|
|
|
float CBridge::DefaultZLiftRoad;
|
|
|
|
float CBridge::DefaultZLiftWeight;
|
2019-07-04 07:04:34 -04:00
|
|
|
|
2020-04-16 15:19:56 -04:00
|
|
|
float CBridge::OldLift;
|
2019-07-04 07:04:34 -04:00
|
|
|
|
2020-04-16 15:19:56 -04:00
|
|
|
uint32 CBridge::TimeOfBridgeBecomingOperational;
|
2019-07-04 07:04:34 -04:00
|
|
|
|
|
|
|
void CBridge::Init()
|
|
|
|
{
|
|
|
|
FindBridgeEntities();
|
2020-02-25 14:01:56 -05:00
|
|
|
OldLift = -1.0f;
|
2019-07-04 07:04:34 -04:00
|
|
|
if (pLiftPart && pWeight)
|
|
|
|
{
|
|
|
|
DefaultZLiftPart = pLiftPart->GetPosition().z;
|
|
|
|
DefaultZLiftWeight = pWeight->GetPosition().z;
|
|
|
|
|
|
|
|
if (pLiftRoad)
|
|
|
|
DefaultZLiftRoad = pLiftRoad->GetPosition().z;
|
|
|
|
|
|
|
|
ThePaths.SetLinksBridgeLights(-330.0, -230.0, -700.0, -588.0, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBridge::Update()
|
|
|
|
{
|
|
|
|
if (!pLiftPart || !pWeight)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OldState = State;
|
|
|
|
|
|
|
|
float liftHeight;
|
|
|
|
|
2019-07-17 16:05:11 -04:00
|
|
|
// Set bridge height and state
|
2019-07-04 07:04:34 -04:00
|
|
|
if (CStats::CommercialPassed)
|
|
|
|
{
|
|
|
|
if (TimeOfBridgeBecomingOperational == 0)
|
|
|
|
TimeOfBridgeBecomingOperational = CTimer::GetTimeInMilliseconds();
|
|
|
|
|
|
|
|
// Time remaining for bridge to become operational
|
|
|
|
// uint16, so after about a minute it overflows to 0 and the cycle repeats
|
|
|
|
uint16 timeElapsed = CTimer::GetTimeInMilliseconds() - TimeOfBridgeBecomingOperational;
|
|
|
|
|
|
|
|
// Calculate lift part height and bridge state
|
|
|
|
if (timeElapsed < 10000)
|
|
|
|
{
|
|
|
|
State = STATE_LIFT_PART_MOVING_DOWN;
|
2020-02-25 14:54:26 -05:00
|
|
|
liftHeight = 25.0f - timeElapsed / 10000.0f * 25.0f;
|
2019-07-04 07:04:34 -04:00
|
|
|
}
|
|
|
|
else if (timeElapsed < 40000)
|
|
|
|
{
|
2020-02-25 14:01:56 -05:00
|
|
|
liftHeight = 0.0f;
|
2019-07-04 07:04:34 -04:00
|
|
|
State = STATE_LIFT_PART_IS_DOWN;
|
|
|
|
}
|
|
|
|
else if (timeElapsed < 50000)
|
|
|
|
{
|
2020-02-25 14:01:56 -05:00
|
|
|
liftHeight = 0.0f;
|
2019-07-04 07:04:34 -04:00
|
|
|
State = STATE_LIFT_PART_ABOUT_TO_MOVE_UP;
|
|
|
|
}
|
|
|
|
else if (timeElapsed < 60000)
|
|
|
|
{
|
|
|
|
State = STATE_LIFT_PART_MOVING_UP;
|
2020-02-25 14:54:26 -05:00
|
|
|
liftHeight = (timeElapsed - 50000) / 10000.0f * 25.0f;
|
2019-07-04 07:04:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-25 14:01:56 -05:00
|
|
|
liftHeight = 25.0f;
|
2019-07-04 07:04:34 -04:00
|
|
|
State = STATE_LIFT_PART_IS_UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-25 14:01:56 -05:00
|
|
|
liftHeight = 25.0f;
|
2019-07-04 07:04:34 -04:00
|
|
|
TimeOfBridgeBecomingOperational = 0;
|
|
|
|
State = STATE_BRIDGE_LOCKED;
|
|
|
|
}
|
2019-07-17 16:05:11 -04:00
|
|
|
|
|
|
|
// Move bridge part
|
|
|
|
if (liftHeight != OldLift)
|
|
|
|
{
|
2020-04-30 06:48:01 -04:00
|
|
|
pLiftPart->GetMatrix().GetPosition().z = DefaultZLiftPart + liftHeight;
|
2019-07-17 16:05:11 -04:00
|
|
|
pLiftPart->GetMatrix().UpdateRW();
|
|
|
|
pLiftPart->UpdateRwFrame();
|
|
|
|
if (pLiftRoad)
|
|
|
|
{
|
2020-04-30 06:48:01 -04:00
|
|
|
pLiftRoad->GetMatrix().GetPosition().z = DefaultZLiftRoad + liftHeight;
|
2019-07-17 16:05:11 -04:00
|
|
|
pLiftRoad->GetMatrix().UpdateRW();
|
|
|
|
pLiftRoad->UpdateRwFrame();
|
|
|
|
}
|
2020-04-30 06:48:01 -04:00
|
|
|
pWeight->GetMatrix().GetPosition().z = DefaultZLiftWeight - liftHeight;
|
2019-07-17 16:05:11 -04:00
|
|
|
pWeight->GetMatrix().UpdateRW();
|
|
|
|
pWeight->UpdateRwFrame();
|
|
|
|
|
|
|
|
OldLift = liftHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (State == STATE_LIFT_PART_ABOUT_TO_MOVE_UP && OldState == STATE_LIFT_PART_IS_DOWN)
|
|
|
|
ThePaths.SetLinksBridgeLights(-330.0, -230.0, -700.0, -588.0, true);
|
|
|
|
else if (State == STATE_LIFT_PART_IS_DOWN && OldState == STATE_LIFT_PART_MOVING_DOWN)
|
|
|
|
ThePaths.SetLinksBridgeLights(-330.0, -230.0, -700.0, -588.0, false);
|
2019-07-04 07:04:34 -04:00
|
|
|
}
|
|
|
|
|
2020-05-03 11:28:54 -04:00
|
|
|
bool CBridge::ShouldLightsBeFlashing()
|
|
|
|
{
|
|
|
|
return State != STATE_LIFT_PART_IS_DOWN;
|
|
|
|
}
|
2019-07-04 07:04:34 -04:00
|
|
|
|
|
|
|
void CBridge::FindBridgeEntities()
|
|
|
|
{
|
|
|
|
pWeight = nil;
|
|
|
|
pLiftRoad = nil;
|
|
|
|
pLiftPart = nil;
|
|
|
|
|
2019-10-16 17:53:25 -04:00
|
|
|
for (int i = CPools::GetBuildingPool()->GetSize()-1; i >= 0; i--) {
|
2019-07-04 07:04:34 -04:00
|
|
|
CBuilding* entry = CPools::GetBuildingPool()->GetSlot(i);
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
if (entry->GetModelIndex() == MI_BRIDGELIFT)
|
|
|
|
pLiftPart = entry;
|
|
|
|
else if (entry->GetModelIndex() == MI_BRIDGEROADSEGMENT)
|
|
|
|
pLiftRoad = entry;
|
|
|
|
else if (entry->GetModelIndex() == MI_BRIDGEWEIGHT)
|
|
|
|
pWeight = entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBridge::ThisIsABridgeObjectMovingUp(int index)
|
|
|
|
{
|
|
|
|
if (index != MI_BRIDGEROADSEGMENT && index != MI_BRIDGELIFT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return State == STATE_LIFT_PART_ABOUT_TO_MOVE_UP || State == STATE_LIFT_PART_MOVING_UP;
|
|
|
|
}
|