Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit ecc13a9

Browse files
committed
Merge branch 'development' into move_to_data
2 parents 97d22dd + 39d769d commit ecc13a9

File tree

12 files changed

+82
-116
lines changed

12 files changed

+82
-116
lines changed

Entities/AHuman.cpp

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,95 +1106,63 @@ bool AHuman::EquipThrowable(bool doEquip)
11061106
return false;
11071107
}
11081108

1109-
1110-
//////////////////////////////////////////////////////////////////////////////////////////
1111-
// Virtual Method: EquipDiggingTool
11121109
//////////////////////////////////////////////////////////////////////////////////////////
1113-
// Description: Switches the currently held device (if any) to the first found digging
1114-
// tool in the inventory. If the held device already is a digging tool,
1115-
// or no digging tool is in inventory, nothing happens.
11161110

1117-
bool AHuman::EquipDiggingTool(bool doEquip)
1118-
{
1111+
bool AHuman::EquipDiggingTool(bool doEquip) {
11191112
if (!(m_pFGArm && m_pFGArm->IsAttached())) {
11201113
return false;
11211114
}
11221115

1123-
if (HDFirearm *heldDeviceAsFirearm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldDevice()); heldDeviceAsFirearm && heldDeviceAsFirearm->IsInGroup("Tools - Diggers")) {
1124-
return true;
1116+
const HDFirearm *strongestDigger = nullptr;
1117+
float strongestDiggerDigStrength = 0;
1118+
bool strongestDiggerIsHeld = false;
1119+
if (const HDFirearm *heldDeviceAsFirearm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldDevice()); heldDeviceAsFirearm && heldDeviceAsFirearm->IsInGroup("Tools - Diggers")) {
1120+
strongestDigger = heldDeviceAsFirearm;
1121+
strongestDiggerDigStrength = heldDeviceAsFirearm->EstimateDigStrength();
1122+
strongestDiggerIsHeld = true;
11251123
}
11261124

1127-
// Go through the inventory looking for the proper device
1128-
for (std::deque<MovableObject *>::iterator itr = m_Inventory.begin(); itr != m_Inventory.end(); ++itr)
1129-
{
1130-
HDFirearm *pTool = dynamic_cast<HDFirearm *>(*itr);
1131-
// Found proper device to equip, so make the switch!
1132-
if (pTool && pTool->IsInGroup("Tools - Diggers"))
1133-
{
1134-
if (doEquip)
1135-
{
1136-
// Erase the inventory entry containing the device we now have switched to
1137-
*itr = 0;
1138-
m_Inventory.erase(itr);
1139-
1140-
// Put back into the inventory what we had in our hands, if anything
1141-
if (HeldDevice *heldDevice = m_pFGArm->GetHeldDevice())
1142-
{
1143-
heldDevice->Deactivate();
1144-
AddToInventoryBack(m_pFGArm->RemoveAttachable(heldDevice));
1145-
}
1146-
1147-
// Now put the device we were looking for and found into the hand
1148-
m_pFGArm->SetHeldDevice(pTool);
1149-
// Move the hand to a poisition so it looks like the new device was drawn from inventory
1150-
m_pFGArm->SetHandPos(m_Pos + m_HolsterOffset.GetXFlipped(m_HFlipped));
1151-
1152-
// Equip shield in BG arm is applicable
1153-
EquipShieldInBGArm();
1154-
1155-
// Play the device switching sound
1156-
if (m_DeviceSwitchSound) { m_DeviceSwitchSound->Play(m_Pos); }
1125+
if (doEquip || !strongestDigger) {
1126+
for (MovableObject *inventoryItem : m_Inventory) {
1127+
if (const HDFirearm *inventoryItemAsFirearm = dynamic_cast<HDFirearm *>(inventoryItem); inventoryItemAsFirearm && inventoryItemAsFirearm->IsInGroup("Tools - Diggers") && inventoryItemAsFirearm->EstimateDigStrength() > strongestDiggerDigStrength) {
1128+
strongestDigger = inventoryItemAsFirearm;
1129+
strongestDiggerDigStrength = inventoryItemAsFirearm->EstimateDigStrength();
1130+
strongestDiggerIsHeld = false;
11571131
}
1132+
}
1133+
}
11581134

1159-
return true;
1160-
}
1161-
}
1135+
if (doEquip && strongestDigger && !strongestDiggerIsHeld) {
1136+
EquipNamedDevice(strongestDigger->GetModuleName(), strongestDigger->GetPresetName(), true);
1137+
}
11621138

1163-
return false;
1139+
return strongestDigger != nullptr;
11641140
}
11651141

1166-
1167-
//////////////////////////////////////////////////////////////////////////////////////////
1168-
// Method: EstimateDigStrength
11691142
//////////////////////////////////////////////////////////////////////////////////////////
1170-
// Description: Estimates what material strength this actor can move through.
11711143

1172-
float AHuman::EstimateDigStrength()
1173-
{
1144+
float AHuman::EstimateDigStrength() const {
11741145
float maxPenetration = Actor::EstimateDigStrength();
11751146

11761147
if (!(m_pFGArm && m_pFGArm->IsAttached())) {
11771148
return maxPenetration;
11781149
}
11791150

1180-
if (HDFirearm *heldDeviceAsHDFirearm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldDevice()); heldDeviceAsHDFirearm && heldDeviceAsHDFirearm->IsInGroup("Tools - Diggers")) {
1151+
if (const HDFirearm *heldDeviceAsHDFirearm = dynamic_cast<HDFirearm *>(m_pFGArm->GetHeldDevice()); heldDeviceAsHDFirearm && heldDeviceAsHDFirearm->IsInGroup("Tools - Diggers")) {
11811152
maxPenetration = std::max(heldDeviceAsHDFirearm->EstimateDigStrength(), maxPenetration);
11821153
}
11831154

1184-
// Go through the inventory looking for the proper device
1185-
for (std::deque<MovableObject *>::iterator itr = m_Inventory.begin(); itr != m_Inventory.end(); ++itr)
1186-
{
1187-
HDFirearm *pTool = dynamic_cast<HDFirearm *>(*itr);
1188-
// Found proper device to equip, so make the switch!
1189-
if (pTool && pTool->IsInGroup("Tools - Diggers"))
1190-
{
1191-
maxPenetration = std::max(pTool->EstimateDigStrength(), maxPenetration);
1155+
for (const MovableObject *inventoryItem : m_Inventory) {
1156+
if (const HDFirearm *inventoryItemAsFirearm = dynamic_cast<const HDFirearm *>(inventoryItem); inventoryItemAsFirearm && inventoryItemAsFirearm->IsInGroup("Tools - Diggers")) {
1157+
maxPenetration = std::max(inventoryItemAsFirearm->EstimateDigStrength(), maxPenetration);
11921158
}
11931159
}
11941160

11951161
return maxPenetration;
11961162
}
11971163

1164+
//////////////////////////////////////////////////////////////////////////////////////////
1165+
11981166

11991167
//////////////////////////////////////////////////////////////////////////////////////////
12001168
// Virtual Method: EquipShield
@@ -3417,7 +3385,7 @@ void AHuman::Update()
34173385
}
34183386
EquipShieldInBGArm();
34193387
m_ArmsState = WEAPON_READY;
3420-
} else if (m_ArmsState == THROWING_RELEASE) {
3388+
} else if (m_ArmsState == THROWING_RELEASE && m_pFGArm) {
34213389
m_pFGArm->AddHandTarget("Adjusted Aim Angle", m_Pos + Vector(m_pFGArm->GetMaxLength() * GetFlipFactor(), -m_pFGArm->GetMaxLength() * 0.5F).RadRotate(adjustedAimAngle));
34223390
} else {
34233391
m_CanActivateBGItem = true;

Entities/AHuman.h

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -534,29 +534,18 @@ DefaultPieMenuNameGetter("Default Human Pie Menu");
534534

535535
bool EquipThrowable(bool doEquip = true);
536536

537-
538-
//////////////////////////////////////////////////////////////////////////////////////////
539-
// Virtual Method: EquipDiggingTool
540-
//////////////////////////////////////////////////////////////////////////////////////////
541-
// Description: Switches the currently held device (if any) to the first found digging
542-
// tool in the inventory. If the held device already is a digging tool,
543-
// or no digging tool is in inventory, nothing happens.
544-
// Arguments: Whether to actually equip any matching item found in the inventory,
545-
// or just report that it's there or not.
546-
// Return value: Whether a digging tool was successfully switched to.
547-
537+
/// <summary>
538+
/// Switches the currently held device (if any) to the strongest digging tool in the inventory.
539+
/// </summary>
540+
/// <param name="doEquip">Whether to actually equip the strongest digging tool, or just report whether a digging tool was found.</param>
541+
/// <returns>Whether or not the strongest digging tool was successfully equipped.</returns>
548542
bool EquipDiggingTool(bool doEquip = true);
549543

550-
551-
//////////////////////////////////////////////////////////////////////////////////////////
552-
// Method: EstimateDigStrength
553-
//////////////////////////////////////////////////////////////////////////////////////////
554-
// Description: Estimates what material strength any digger this actor is carrying
555-
// can penetrate.
556-
// Arguments: None.
557-
// Return value: A default dig strength (what the actor can be expected to just walk through without tools), or the maximum material strength this actor's digger can penetrate.
558-
559-
float EstimateDigStrength() override;
544+
/// <summary>
545+
/// Estimates what material strength any digger this AHuman is carrying can penetrate.
546+
/// </summary>
547+
/// <returns>The maximum material strength this AHuman's digger can penetrate, or a default dig strength if they don't have a digger.</returns>
548+
float EstimateDigStrength() const override;
560549

561550

562551
//////////////////////////////////////////////////////////////////////////////////////////

Entities/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ bool Actor::UpdateMovePath()
12911291

12921292
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12931293

1294-
float Actor::EstimateDigStrength() {
1294+
float Actor::EstimateDigStrength() const {
12951295
return m_AIBaseDigStrength;
12961296
}
12971297

Entities/Actor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ ClassInfoGetters;
11271127
/// Estimates what material strength this actor can penetrate.
11281128
/// </summary>
11291129
/// <returns>The actor's dig strength.</returns>
1130-
virtual float EstimateDigStrength();
1130+
virtual float EstimateDigStrength() const;
11311131

11321132
/// <summary>
11331133
/// Gets this Actor's base dig strength, or the strength of terrain they can expect to walk through without tools.

Entities/HDFirearm.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,13 +1115,8 @@ void HDFirearm::Update()
11151115
//////////////////////////////////////////////////////////////////////////////////////////
11161116
// Description: Estimates what material strength the rounds in the magazine can destroy.
11171117

1118-
float HDFirearm::EstimateDigStrength()
1119-
{
1120-
if (m_pMagazine) {
1121-
return m_pMagazine->EstimateDigStrength();
1122-
}
1123-
1124-
return 1;
1118+
float HDFirearm::EstimateDigStrength() const {
1119+
return m_pMagazine ? m_pMagazine->EstimateDigStrength() : m_pMagazineReference->EstimateDigStrength();
11251120
}
11261121

11271122

Entities/HDFirearm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ AddScriptFunctionNames(HeldDevice, "OnFire", "OnReload");
796796
// Arguments: None.
797797
// Return value: The maximum material strength the regular or the tracer round can destroy.
798798

799-
float EstimateDigStrength();
799+
float EstimateDigStrength() const;
800800

801801

802802
//////////////////////////////////////////////////////////////////////////////////////////

Entities/Magazine.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ Round * Magazine::PopNextRound()
225225
//////////////////////////////////////////////////////////////////////////////////////////
226226
// Description: Estimates what material strength the rounds in the magazine can destroy.
227227

228-
float Magazine::EstimateDigStrength()
229-
{
228+
float Magazine::EstimateDigStrength() const {
230229
float maxPenetration = 1;
231230
if (m_pTracerRound)
232231
{

Entities/Magazine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ ClassInfoGetters;
206206
// Arguments: None.
207207
// Return value: The material strength.
208208

209-
float EstimateDigStrength();
209+
float EstimateDigStrength() const;
210210

211211

212212
//////////////////////////////////////////////////////////////////////////////////////////

Managers/UInputMan.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,14 @@ namespace RTE {
191191
case InputDevice::DEVICE_KEYB_ONLY:
192192
if (ElementHeld(player, InputElements::INPUT_L_UP)) {
193193
allInput.m_Y += -1.0F;
194-
} else if (ElementHeld(player, InputElements::INPUT_L_DOWN)) {
194+
}
195+
if (ElementHeld(player, InputElements::INPUT_L_DOWN)) {
195196
allInput.m_Y += 1.0F;
196-
} else if (ElementHeld(player, InputElements::INPUT_L_LEFT)) {
197+
}
198+
if (ElementHeld(player, InputElements::INPUT_L_LEFT)) {
197199
allInput.m_X += -1.0F;
198-
} else if (ElementHeld(player, InputElements::INPUT_L_RIGHT)) {
200+
}
201+
if (ElementHeld(player, InputElements::INPUT_L_RIGHT)) {
199202
allInput.m_X += 1.0F;
200203
}
201204
break;
@@ -800,6 +803,7 @@ namespace RTE {
800803
m_NetworkAccumulatedRawMouseMovement[Players::PlayerOne] += m_RawMouseMovement;
801804
}
802805
UpdateMouseInput();
806+
UpdateJoystickDigitalAxis();
803807
HandleSpecialInput();
804808
StoreInputEventsForNextUpdate();
805809

@@ -996,19 +1000,9 @@ namespace RTE {
9961000
int joystickIndex = device - s_PrevJoystickStates.begin();
9971001

9981002
int prevAxisValue = device->m_Axis[axis];
999-
int prevDigitalValue = device->m_DigitalAxis[axis];
1000-
1001-
int newDigitalState = 0;
1002-
if (value > c_AxisDigitalThreshold) {
1003-
newDigitalState = 1;
1004-
} else if (value < -c_AxisDigitalThreshold) {
1005-
newDigitalState = -1;
1006-
}
10071003

10081004
s_ChangedJoystickStates[joystickIndex].m_Axis[axis] = Sign(value - device->m_Axis[axis]);
1009-
s_ChangedJoystickStates[joystickIndex].m_DigitalAxis[axis] = Sign(newDigitalState - prevDigitalValue);
10101005
device->m_Axis[axis] = value;
1011-
device->m_DigitalAxis[axis] = newDigitalState;
10121006

10131007
Players joystickPlayer = Players::NoPlayer;
10141008
float deadZone = 0.0F;
@@ -1051,30 +1045,45 @@ namespace RTE {
10511045
if (aimValues.MagnitudeIsLessThan(deadZone)) {
10521046
if (axisLeft != SDL_CONTROLLER_AXIS_INVALID) {
10531047
s_ChangedJoystickStates[joystickIndex].m_Axis[axisLeft] = Sign(axisLeft == axis ? -prevAxisValue : -device->m_Axis[axisLeft]);
1054-
s_ChangedJoystickStates[joystickIndex].m_DigitalAxis[axisLeft] = Sign(axisLeft == axis ? -prevDigitalValue : -device->m_DigitalAxis[axisLeft]);
10551048
device->m_Axis[axisLeft] = 0;
1056-
device->m_DigitalAxis[axisLeft] = 0;
10571049
}
10581050
if (axisUp != SDL_CONTROLLER_AXIS_INVALID) {
10591051
s_ChangedJoystickStates[joystickIndex].m_Axis[axisUp] = Sign(axisUp == axis ? -prevAxisValue : -device->m_Axis[axisUp]);
1060-
s_ChangedJoystickStates[joystickIndex].m_DigitalAxis[axisUp] = Sign(axisLeft == axis ? -prevDigitalValue : -device->m_DigitalAxis[axisUp]);
10611052
device->m_Axis[axisUp] = 0;
1062-
device->m_DigitalAxis[axisUp] = 0;
10631053
}
10641054
}
10651055
} else if (deadZoneType == DeadZoneType::SQUARE && deadZone > 0.0F) {
10661056
if (std::abs(static_cast<double>(value) / c_GamepadAxisLimit) < deadZone) {
10671057
s_ChangedJoystickStates[joystickIndex].m_Axis[axis] = Sign(-prevAxisValue);
1068-
s_ChangedJoystickStates[joystickIndex].m_Axis[axis] = Sign(-prevDigitalValue);
10691058
device->m_Axis[axis] = 0;
1070-
device->m_DigitalAxis[axis] = 0;
10711059
}
10721060
}
10731061
}
10741062
}
10751063
}
10761064
}
10771065

1066+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1067+
1068+
void UInputMan::UpdateJoystickDigitalAxis() {
1069+
for (size_t i = 0; i < s_PrevJoystickStates.size(); ++i) {
1070+
for (size_t axis = 0; axis < s_PrevJoystickStates[i].m_DigitalAxis.size(); ++axis) {
1071+
int prevDigitalValue = s_PrevJoystickStates[i].m_DigitalAxis[axis];
1072+
int newDigitalValue = 0;
1073+
if (prevDigitalValue != 0 && std::abs(s_PrevJoystickStates[i].m_Axis[axis]) > c_AxisDigitalReleasedThreshold) {
1074+
newDigitalValue = prevDigitalValue;
1075+
}
1076+
if (s_PrevJoystickStates[i].m_Axis[axis] > c_AxisDigitalPressedThreshold) {
1077+
newDigitalValue = 1;
1078+
} else if (s_PrevJoystickStates[i].m_Axis[axis] < -c_AxisDigitalPressedThreshold) {
1079+
newDigitalValue = -1;
1080+
}
1081+
s_ChangedJoystickStates[i].m_DigitalAxis[axis] = Sign(newDigitalValue - prevDigitalValue);
1082+
s_PrevJoystickStates[i].m_DigitalAxis[axis] = newDigitalValue;
1083+
}
1084+
}
1085+
}
1086+
10781087
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10791088

10801089
void UInputMan::HandleGamepadHotPlug(int deviceIndex) {

Managers/UInputMan.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,8 @@ namespace RTE {
712712
bool m_TrapMousePosPerPlayer[Players::MaxPlayerCount]; //!< Whether to trap the mouse position to the middle of the screen for each player during network multiplayer.
713713

714714
static constexpr double c_GamepadAxisLimit = 32767.0; //!< Maximum axis value as defined by SDL (int16 max).
715-
static constexpr int c_AxisDigitalThreshold = 8192; //!< Digital Axis threshold value as defined by allegro.
715+
static constexpr int c_AxisDigitalPressedThreshold = 8192; //!< Digital Axis threshold value as defined by allegro.
716+
static constexpr int c_AxisDigitalReleasedThreshold = c_AxisDigitalPressedThreshold - 100; //!< Digital Axis release threshold, to debounce values.
716717

717718
#pragma region Input State Handling
718719
/// <summary>
@@ -826,6 +827,11 @@ namespace RTE {
826827
/// </summary>
827828
void UpdateJoystickAxis(std::vector<Gamepad>::iterator device, int axis, int newValue);
828829

830+
/// <summary>
831+
/// Updates simulated digital joystick axis. This is called from Update().
832+
/// </summary>
833+
void UpdateJoystickDigitalAxis();
834+
829835
/// <summary>
830836
/// Connect a joystick or gamepad device and add it to the joystick list if a slot is available (up to max player count).
831837
/// </summary>

0 commit comments

Comments
 (0)