Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIWS v2 #3534

Open
wants to merge 129 commits into
base: Development
Choose a base branch
from
Open

CIWS v2 #3534

wants to merge 129 commits into from

Conversation

MaxDorob
Copy link
Contributor

@MaxDorob MaxDorob commented Nov 5, 2024

Additions

Describe new functionality added by your code

  • Multi verb turret
  • CIWS turret
  • Projectile, skyfaller CIWS verb (and verb that targets things with CompCIWSTarget childs)
  • Trajectory workers (mostly necessary because we need to know the trajectory before we launch projectile)
    • LerpedTrajectoryWorker - original trajectory
    • BallisticsTrajectoryWorker - non-lerped trajectory worker, mostly moved code from ProjectileCE
    • SmartRocketTrajectoryWorker - trajectory worker for projectile that chase target
  • ProjectilePropertiesCE
    • speedGain (float)
    • collideDistance and impactChance (float, used for CIWS projectile)
    • CIWSVersion (ThingDef, used to swap projectiles when CIWS verbs used)
    • trajectoryWorker (Type, if not specified LerpedTrajectoryWorker is used (BallisticsTrajectoryWorker if lerpPosition false))

Changes

Describe adjustments to existing features made in this merge

  • Changed some base verb methods
  • Moved some trajectory work to worker class (because we need to know trajectory before launch)

References

ToDo

  • Skyfaller verb targeting
  • TurretTop aim line
  • Improve accuracy
  • Unlock rotation in mid burst for CIWS
  • CompCIWSTarget for skyfaller (similar to VerbCIWSSkyfaller, but for third party skyfaller should be intercepted)
  • Fix CIWS projectile hits ground
  • Fix incorrect direction for first CIWS shot
  • Fix VFX position on intercepted
  • IgnoredDefs
  • Hold fire option
  • VFX
  • Smart rockets trajectory worker
  • Performance
  • Code cleanup
  • Delete/move example defs
  • Move verbs to correct folder

Testing

Check tests you have performed:

  • Compiles without warnings
  • Game runs without errors
  • Playtested a colony (tested few variants of CIWS and other weapons)

Examples

Turrets should use projectiles with thingClass ProjectileCE_CIWS.
You can specify CIWS version in def with CIWSVersion node like this:

<ThingDef Name="Bullet_8x35mmCharged" ParentName="Base8x35mmChargedBullet">
		<defName>Bullet_8x35mmCharged</defName>
		<label>8x35mm Charged bullet</label>
		<projectile Class="CombatExtended.ProjectilePropertiesCE">
      <CIWSVersion>Bullet_8x35mmChargedCIWS</CIWSVersion>
			<damageAmountBase>19</damageAmountBase>
			<secondaryDamage>
				<li>
					<def>Bomb_Secondary</def>
					<amount>6</amount>
				</li>
			</secondaryDamage>
			<armorPenetrationSharp>16</armorPenetrationSharp>
			<armorPenetrationBlunt>57.6</armorPenetrationBlunt>
		</projectile>
	</ThingDef>
	...

  <ThingDef Name="Bullet_8x35mmChargedCIWS" ParentName="Base8x35mmChargedBullet">
    <defName>Bullet_8x35mmChargedCIWS</defName>
    <thingClass>CombatExtended.ProjectileCE_CIWS</thingClass>
    <label>8x35mm Charged bullet</label>
    <projectile Class="CombatExtended.ProjectilePropertiesCE">
      <damageAmountBase>19</damageAmountBase>
      <secondaryDamage>
        <li>
          <def>Bomb_Secondary</def>
          <amount>6</amount>
        </li>
      </secondaryDamage>
      <armorPenetrationSharp>16</armorPenetrationSharp>
      <armorPenetrationBlunt>57.6</armorPenetrationBlunt>
      <trajectoryWorker>CombatExtended.LerpedTrajectoryWorker_ExactPosDrawing</trajectoryWorker>
    </projectile>
  </ThingDef>

CIWS must use Building_CIWS_CE as thingClass

<!--=============== Blaster CIWS ===============-->

	<ThingDef ParentName="TurretAutoBase">
		<defName>CIWS_Blaster</defName>
    <thingClass>CombatExtended.Building_CIWS_CE</thingClass>
		<label>charge blaster CIWS</label>
		<constructionSkillPrerequisite>8</constructionSkillPrerequisite>
		<graphicData>
			<texPath>Things/Building/Turrets/MachineGunBase</texPath>
			<shadowData>
				<volume>(0.27,0.25,0.27)</volume>
				<offset>(0,0,0)</offset>
			</shadowData>
		</graphicData>
		<uiIconPath>UI/Icons/Turrets/ChargeBlaster_uiIcon</uiIconPath>
		<statBases>
			<WorkToBuild>23000</WorkToBuild>
			<MaxHitPoints>150</MaxHitPoints>
			<Mass>20</Mass>
			<Bulk>25</Bulk>
			<AimingAccuracy>0.75</AimingAccuracy>
			<ShootingAccuracyTurret>1.25</ShootingAccuracyTurret>
			<NightVisionEfficiency>0.5</NightVisionEfficiency>
		</statBases>
		<techLevel>Spacer</techLevel>
		<comps>
			<li Class="CompProperties_Power">
				<compClass>CompPowerTrader</compClass>
				<basePowerConsumption>400</basePowerConsumption>
			</li>
		</comps>
		<description>Automatic turret equipped with a charge blaster.</description>
		<costList>
			<Steel>125</Steel>
			<Plasteel>40</Plasteel>
			<ComponentIndustrial>6</ComponentIndustrial>
			<ComponentSpacer>1</ComponentSpacer>
		</costList>
		<building>
			<turretGunDef>Gun_CIWSBlasterTurret</turretGunDef>
			<ai_combatDangerous>true</ai_combatDangerous>
		</building>
		<designatorDropdown>CE_AutoTurrets</designatorDropdown>
		<placeWorkers>
			<li>PlaceWorker_TurretTop</li>
			<li>PlaceWorker_ShowTurretRadius</li>
		</placeWorkers>
		<researchPrerequisites>
			<li>CE_ChargeTurret</li>
		</researchPrerequisites>
		<minifiedDef>MinifiedThing</minifiedDef>
	</ThingDef>

Gun of such CIWS may have few attack verbs unlike usual turret.
Usual attack verb (non CIWS) must be specified first (otherwise turret may ignore it).
Also you may specify CompVerbDisabler in comps to make CIWS disablable.
Example of such gun:

	<ThingDef ParentName="BaseAutoTurretGun">
		<defName>Gun_CIWSBlasterTurret</defName>
		<label>blaster turret gun</label>
		<graphicData>
			<texPath>Things/Building/Turrets/BlasterTurret_Top</texPath>
			<graphicClass>Graphic_Single</graphicClass>
		</graphicData>
		<description>Charge blaster attached to a turret mount.</description>
		<soundInteract>Interact_ChargeRifle</soundInteract>
		<statBases>
			<SightsEfficiency>1</SightsEfficiency>
			<ShotSpread>0.06</ShotSpread>
			<SwayFactor>0.86</SwayFactor>
			<RangedWeapon_Cooldown>0.36</RangedWeapon_Cooldown>
			<Mass>10</Mass>
		</statBases>
		<verbs>
			<li Class="CombatExtended.VerbPropertiesCE">
				<recoilAmount>0.90</recoilAmount>
				<verbClass>CombatExtended.Verb_ShootCE</verbClass>
				<hasStandardCommand>true</hasStandardCommand>
				<defaultProjectile>Bullet_8x35mmCharged</defaultProjectile>
				<warmupTime>1.3</warmupTime>
				<range>55</range>
				<ticksBetweenBurstShots>5</ticksBetweenBurstShots>
				<burstShotCount>10</burstShotCount>
				<soundCast>Shot_ChargeBlaster</soundCast>
				<soundCastTail>GunTail_Heavy</soundCastTail>
				<muzzleFlashScale>9</muzzleFlashScale>
				<recoilPattern>Mounted</recoilPattern>
			</li>
      <li Class="CombatExtended.VerbProperties_CIWSProjectile">
        <verbClass>CombatExtended.VerbCIWSProjectile</verbClass>
        <recoilAmount>0.90</recoilAmount>
        <hasStandardCommand>true</hasStandardCommand>
        <defaultProjectile>Bullet_8x35mmCharged</defaultProjectile>
        <warmupTime>0.4</warmupTime>
        <range>105</range>
        <ticksBetweenBurstShots>5</ticksBetweenBurstShots>
        <burstShotCount>10</burstShotCount>
        <soundCast>Shot_ChargeBlaster</soundCast>
        <soundCastTail>GunTail_Heavy</soundCastTail>
        <muzzleFlashScale>9</muzzleFlashScale>
        <recoilPattern>Mounted</recoilPattern>
        <holdFireLabel>HoldCloseInProjectilesFire</holdFireLabel>
        <holdFireDesc>HoldCloseInProjectilesFireDesc</holdFireDesc>
      </li>
      <li Class="CombatExtended.VerbProperties_CIWSSkyfaller">
        <verbClass>CombatExtended.VerbCIWSSkyfaller</verbClass>
        <recoilAmount>0.90</recoilAmount>
        <hasStandardCommand>true</hasStandardCommand>
        <defaultProjectile>Bullet_8x35mmCharged</defaultProjectile>
        <warmupTime>0.4</warmupTime>
        <range>105</range>
        <ticksBetweenBurstShots>5</ticksBetweenBurstShots>
        <burstShotCount>10</burstShotCount>
        <soundCast>Shot_ChargeBlaster</soundCast>
        <soundCastTail>GunTail_Heavy</soundCastTail>
        <muzzleFlashScale>9</muzzleFlashScale>
        <recoilPattern>Mounted</recoilPattern>
        <holdFireLabel>HoldCloseInSkyfallersFire</holdFireLabel>
      </li>
		</verbs>
		<comps>
			<li Class="CombatExtended.CompProperties_AmmoUser">
				<magazineSize>100</magazineSize>
				<reloadTime>7.8</reloadTime>
				<ammoSet>AmmoSet_8x35mmCharged</ammoSet>
			</li>
      <li>
        <compClass>CombatExtended.CompVerbDisabler</compClass>
      </li>
		</comps>
	</ThingDef>

Example of smart rocket, that use specific trajectory worker

	<ThingDef Name="Base50mmRocket" ParentName="BaseExplosiveBullet" Abstract="true">
		...
		<projectile Class="CombatExtended.ProjectilePropertiesCE">
			...
      <ballisticCoefficient>1.0</ballisticCoefficient>
      <mass>1.0</mass>
      <diameter>2</diameter>
		</projectile>
	</ThingDef>

	<ThingDef ParentName="Base50mmRocket">
		<defName>Bullet_50mmRocket_HE</defName>
		...
		<projectile Class="CombatExtended.ProjectilePropertiesCE">
                 ...
      <CIWSVersion>Bullet_50mmRocket_HE_CIWS</CIWSVersion>
		</projectile>
		...
	</ThingDef>

  <ThingDef ParentName="Base50mmRocket">
    <defName>Bullet_50mmRocket_HE_CIWS</defName>
    <thingClass>CombatExtended.ProjectileCE_CIWS</thingClass>
    <label>50mm rocket (HE)</label>
    <graphicData>
      <texPath>Things/Projectile/Rocket/70mmAPKWS</texPath>
      <graphicClass>Graphic_Single</graphicClass>
      <drawSize>0.70</drawSize>
    </graphicData>
    <projectile Class="CombatExtended.ProjectilePropertiesCE">
      <damageDef>Bomb</damageDef>
      <damageAmountBase>147</damageAmountBase>
      <explosionRadius>0</explosionRadius>
      <trajectoryWorker>CombatExtended.SmartRocketTrajectoryWorker</trajectoryWorker>
      <speed>120</speed>
      <speedGain>32</speedGain>
    </projectile>
    ...
  </ThingDef>
  
  <ThingDef>
     <defName>Turret_RocketswarmLauncher</defName>
     <thingClass>CombatExtended.Building_CIWS_CE</thingClass>
     ...
  </ThingDef>

Copy link

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12097015705.zip

Copy link

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12097281167.zip

Copy link

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12097480056.zip

Copy link

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12097511410.zip

float speedGain,
float maxSpeed,
int flightTicks)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: It might simplify things to pack all these parameters into a ref struct and pass that around instead. Right now the full parameter list has to be spelled out in a lot of places.

private Thing TryDropThing(Thing thing, Map map, IntVec3 position)
{
var contents = (parent as IActiveDropPod)?.Contents;
Rot4 rot = (contents?.setRotation != null) ? contents.setRotation.Value : Rot4.North;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could return early if contents are null here and spare a lot of null checks down the line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rimworld ActiveDropPod.OpenPod works the same way, so is it really worth it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth it since this code will now live in CE, so simplifying things will make life easier for future us.

Copy link

github-actions bot commented Dec 2, 2024

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12126067072.zip

Copy link

github-actions bot commented Dec 3, 2024

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12146271401.zip

Copy link

github-actions bot commented Dec 3, 2024

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12146321943.zip

Copy link

github-actions bot commented Dec 3, 2024

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12146488676.zip

Copy link

github-actions bot commented Dec 3, 2024

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12146666738.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Download in Comments This PR has a zipfile download available.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants