Skip to content

Commit

Permalink
scale up
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Mar 20, 2024
1 parent 3948f04 commit 688eb23
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ This page lists all the individual contributions to the project by their author.
- Facing towards target even if not omni-firing
- Turret direction in idle state fix
- Sensor fix
- Allow to tilt on ground
- Allow to tilt regardless of TiltCrashJumpjet
- Forbid firing when crashing
- OmniFire.TurnToTarget
- RecoilForce
- Object Self-destruction logic
- Misc vanilla suicidal behavior fix
- Post-type-conversion update
Expand Down
2 changes: 1 addition & 1 deletion docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- Animation with `Tiled=yes` now supports `CustomPalette`.
- Attempted to avoid units from retaining previous orders (attack,grind,garrison,etc) after changing ownership (mind-control,abduction,etc).
- Fixed buildings' `NaturalParticleSystem` being created for in-map pre-placed structures.
- Fixed jumpjet units being unable to visually tilt or be flipped over on the ground if `TiltCrashJumpjet=no`.
- Fixed jumpjet units being unable to visually tilt or be flipped if `TiltCrashJumpjet=no`.
- Unlimited (more than 5) `AlternateFLH` entries for units.
- Warheads spawning debris now use `MaxDebris` as an actual cap for number of debris to spawn instead of `MaxDebris` - 1.
If both `Primary` and `Secondary` weapons can fire at air targets (projectile has `AA=true`), `Primary` can now be picked instead of always forcing `Secondary`. Also applies to `IsGattling=true`, with odd-numbered and even-numbered `WeaponX` slots instead of `Primary` and `Secondary`, respectively.
Expand Down
14 changes: 13 additions & 1 deletion docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ ForceWeapon.Disguised=-1 ; integer. 0 for primary weapon, 1 for secondary

### Make units try turning to target when firing with `OmniFire=yes`
- The unit will try to turn the body to target even firing with `OmniFire=yes`
- Recommended for jumpjets if you want it to turn to target when firing.
- Jumpjets are recommended to have the same value of body `ROT` and `JumpjetTurnRate`

In `rulesmd.ini`:
```ini
Expand Down Expand Up @@ -1288,6 +1288,18 @@ In `rulesmd.ini`:
FeedbackWeapon= ; WeaponType
```

### Recoil force

- You can now tilt a voxel unit after firing to simulate the recoil force.
- The body's "moment of inertia" is simplified to be linearly proportional to the body voxel's size. Turret voxel is not considered yet. Therefore you must have a visible size voxel body.

In `rulesmd.ini`:
```ini
[SOMEWEAPON] ; WeaponType
RecoilForce= ; floating point value
```


### Radiation enhancements

- In addition to allowing custom radiation types, several enhancements are also available to the default radiation type defined in `[Radiation]`, such as ability to set owner & invoker or deal damage against buildings. See [Custom Radiation Types](#custom-radiation-types) for more details.
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ New:
- Projectile return weapon (by Starkku)
- Allow customizing aircraft landing direction per aircraft or per dock (by Starkku)
- Allow animations to play sounds detached from audio event handler (by Starkku)
- Voxel unit weapon recoil force (by Trsdy)
- Game save option when starting campaigns (by Trsdy)
- Carryall pickup voice (by Starkku)
- Option to have `Grinding.Weapon` require accumulated credits from grinding (by Starkku)
Expand Down
50 changes: 30 additions & 20 deletions src/Ext/Unit/Hooks.Jumpjet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include <Ext/TechnoType/Body.h>
#include <Ext/WeaponType/Body.h>

// Bugfix: Jumpjet turn to target when attacking

// Jumpjets stuck at FireError::FACING because WW didn't use a correct facing
// Misc jumpjet facing, turning, drawing fix, Misc loco drawing fix -- Author: Trsdy
// Jumpjets stuck at FireError::FACING because Jumpjet has its own facing just for JumpjetTurnRate
// We should not touch the linked unit's PrimaryFacing when it's moving and just let the loco sync this shit in 54D692
// The body facing never actually turns, it just syncs
DEFINE_HOOK(0x736F78, UnitClass_UpdateFiring_FireErrorIsFACING, 0x6)
{
GET(UnitClass* const, pThis, ESI);
Expand Down Expand Up @@ -79,6 +80,17 @@ DEFINE_HOOK(0x736EE9, UnitClass_UpdateFiring_FireErrorIsOK, 0x6)
return 0;
}

void __stdcall JumpjetLocomotionClass_DoTurn(ILocomotion* iloco, DirStruct dir)
{
__assume(iloco != nullptr);
// This seems to be used only when unloading shit on the ground
// Rewrite just in case
auto pThis = static_cast<JumpjetLocomotionClass*>(iloco);
pThis->LocomotionFacing.SetDesired(dir);
pThis->LinkedTo->PrimaryFacing.SetDesired(dir);
}
DEFINE_JUMP(VTABLE, 0x7ECDB4, GET_OFFSET(JumpjetLocomotionClass_DoTurn))

DEFINE_HOOK(0x54D326, JumpjetLocomotionClass_MovementAI_CrashSpeedFix, 0x6)
{
GET(JumpjetLocomotionClass*, pThis, ESI);
Expand Down Expand Up @@ -115,10 +127,9 @@ DEFINE_HOOK(0x736BA3, UnitClass_UpdateRotation_TurretFacing_Jumpjet, 0x6)
// When jumpjets arrived at their FootClass::Destination, they seems stuck at the Move mission
// and therefore the turret facing was set to DirStruct{atan2(0,0)}==DirType::East at 0x736BBB
// that's why they will come back to normal when giving stop command explicitly
auto pType = pThis->Type;
// so the best way is to fix the Mission if necessary, but I don't know how to do it
// so I skipped jumpjets check temporarily, and in most cases Jumpjet/BallonHover should cover most of it
if (!pType->TurretSpins && (pType->JumpJet || pType->BalloonHover))
// so I skipped jumpjets check temporarily
if (!pThis->Type->TurretSpins && locomotion_cast<JumpjetLocomotionClass*>(pThis->Locomotor))
return SkipCheckDestination;

return 0;
Expand Down Expand Up @@ -153,30 +164,29 @@ DEFINE_HOOK(0x54CB0E, JumpjetLocomotionClass_State5_CrashSpin, 0x7)
return pTypeExt->JumpjetRotateOnCrash ? 0 : 0x54CB3E;
}


// These are subject to changes if someone wants to properly implement jumpjet tilting
DEFINE_HOOK(0x54DCCF, JumpjetLocomotionClass_DrawMatrix_TiltCrashJumpjet, 0x5)
// We no longer explicitly check TiltCrashJumpjet when drawing, do it when crashing
DEFINE_HOOK(0x70B649, TechnoClass_RigidBodyDynamics_NoTiltCrashBlyat, 0x6)
{
GET(ILocomotion*, iloco, ESI);
__assume(iloco != nullptr);
//if (static_cast<JumpjetLocomotionClass*>(iloco)->State < JumpjetLocomotionClass::State::Crashing)
if (static_cast<JumpjetLocomotionClass*>(iloco)->State == JumpjetLocomotionClass::State::Grounded)
return 0x54DCE8;
GET(FootClass*, pThis, ESI);

if (locomotion_cast<JumpjetLocomotionClass*>(pThis->Locomotor) && !pThis->GetTechnoType()->TiltCrashJumpjet)
return 0x70BCA4;

return 0;
}

/*
DEFINE_JUMP(LJMP, 0x54DCCF, 0x54DCE8);//JumpjetLocomotionClass_DrawMatrix_NoTiltCrashJumpjetHereBlyat
// and the tilt center looked bad visually
DEFINE_HOOK(0x54DD3D, JumpjetLocomotionClass_DrawMatrix_AxisCenterInAir, 0x5)
{
GET(ILocomotion*, iloco, ESI);
__assume(iloco != nullptr);
auto state = static_cast<JumpjetLocomotionClass*>(iloco)->State;
if (state && state < JumpjetLocomotionClass::State::Crashing)
return 0x54DE88;
return 0;

if (static_cast<JumpjetLocomotionClass*>(iloco)->State == JumpjetLocomotionClass::State::Grounded)
return 0;

return 0x54DE88;
}
*/

FireError __stdcall JumpjetLocomotionClass_Can_Fire(ILocomotion* pThis)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/WeaponType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void WeaponTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->ExtraWarheads_DamageOverrides.Read(exINI, pSection, "ExtraWarheads.DamageOverrides");
this->AmbientDamage_Warhead.Read(exINI, pSection, "AmbientDamage.Warhead");
this->AmbientDamage_IgnoreTarget.Read(exINI, pSection, "AmbientDamage.IgnoreTarget");
this->RecoilForce.Read(exINI, pSection, "RecoilForce");
}

template <typename T>
Expand Down Expand Up @@ -88,6 +89,7 @@ void WeaponTypeExt::ExtData::Serialize(T& Stm)
.Process(this->ExtraWarheads_DamageOverrides)
.Process(this->AmbientDamage_Warhead)
.Process(this->AmbientDamage_IgnoreTarget)
.Process(this->RecoilForce)
;
};

Expand Down
2 changes: 2 additions & 0 deletions src/Ext/WeaponType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class WeaponTypeExt
ValueableVector<int> ExtraWarheads_DamageOverrides;
Nullable<WarheadTypeClass*> AmbientDamage_Warhead;
Valueable<bool> AmbientDamage_IgnoreTarget;
Valueable<double> RecoilForce;

ExtData(WeaponTypeClass* OwnerObject) : Extension<WeaponTypeClass>(OwnerObject)
, DiskLaser_Radius { DiskLaserClass::Radius }
Expand All @@ -64,6 +65,7 @@ class WeaponTypeExt
, ExtraWarheads_DamageOverrides {}
, AmbientDamage_Warhead {}
, AmbientDamage_IgnoreTarget { false }
, RecoilForce { 0 }
{ }

int GetBurstDelay(int burstIndex);
Expand Down
24 changes: 23 additions & 1 deletion src/Ext/WeaponType/Hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Body.h"

#include <UnitClass.h>
#include <Ext/BulletType/Body.h>

DEFINE_HOOK(0x772A0A, WeaponTypeClass_SetSpeed_ApplyGravity, 0x6)
Expand All @@ -22,3 +22,25 @@ DEFINE_HOOK(0x773087, WeaponTypeClass_GetSpeed_ApplyGravity, 0x6)
return 0x7730A3;
}


// An example for quick tilting test
DEFINE_HOOK(0x7413DD, UnitClass_Fire_RecoilForce, 0x6)
{
GET(UnitClass* const, pThis, ESI);
if (pThis->Transporter || !pThis->IsVoxel())
return 0;

GET(BulletClass* const, pTraj, EDI);

auto force = WeaponTypeExt::ExtMap.Find(pTraj->WeaponType)->RecoilForce.Get();

if (std::abs(force) < 0.002)
return 0;

const double theta = pThis->GetRealFacing().GetRadian<32>() - pThis->PrimaryFacing.Current().GetRadian<32>();

pThis->RockingForwardsPerFrame = (float)(-force * Math::cos(theta) * Math::cos(pThis->AngleRotatedForwards) / pThis->Type->VoxelScaleY);
pThis->RockingSidewaysPerFrame = (float)(force * Math::sin(theta) * Math::cos(pThis->AngleRotatedSideways) / pThis->Type->VoxelScaleX);

return 0;
}

0 comments on commit 688eb23

Please sign in to comment.