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

Feat(ships): Add "auto explosion" tag to create explosions fitting to the ship #10071

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

RisingLeaf
Copy link
Contributor

@RisingLeaf RisingLeaf commented May 18, 2024

Feature

This PR addresses the bug/feature described in my dreams a stream by saug

Summary

This takes the default explosion formula from the wiki:

"blast radius" (Typical value: (shields + hull) * .01)
"shield damage" (Typical value: (shields + hull) * .10)
"hull damage" (Typical value: (shields + hull) * .05)
"hit force" (Typical value: (shields + hull) * .15)

and implements it in game with the name "auto explosion"
it can be useful for not having the worry about changing explosion values every time you change the ships hull/shields as it updates them automatically, note that this only works in data files and not in saves, as the automatically created weapon will be normally saved

full syntax:

ship
	"auto explosion" <base multiplier, default: 1>
			"blast radius" <multiplier, default: 0.01>
			"shield damage" <multiplier, default: 0.10>
			"hull damage" <multiplier, default: 0.05>
			"hit force" <multiplier, default: 0.15>

final calculation:

blast radius = (shields + hull) * baseMult * radiusMult
shield damage = (shields + hull) * baseMult * shieldMult
hull damage = (shields + hull) * baseMult * hullMult
hit force = (shields + hull) * baseMult * forceMult

Usage examples

Instead of:

ship "Arrow"
	sprite "ship/arrow"
	thumbnail "thumbnail/arrow"
	attributes
		category "Transport"
		"cost" 1200000
		"shields" 2000
		"hull" 400
		[...]
		weapon
			"blast radius" 24
			"shield damage" 240
			"hull damage" 120
			"hit force" 360

now do:

ship "Arrow"
	sprite "ship/arrow"
	thumbnail "thumbnail/arrow"
	attributes
		category "Transport"
		"cost" 1200000
		"shields" 2000
		"hull" 400
		[...]
	"auto explosion"

Testing Done

not yet

@RisingLeaf
Copy link
Contributor Author

RisingLeaf commented May 18, 2024

Note: could be expanded to add a multiplier to support higher tiers quality ships

@Amazinite
Copy link
Collaborator

Amazinite commented May 18, 2024

Bear in mind that MZ eventually ditched this formula for T2+ ships because the explosions ended up getting way too big.

I think it'd make sense to allow this token to have a decimal value next to it that can be used to scale the default explosion. So "auto explosion" 0.5 would take the specified formulas and multiply their outputs by 0.5 to determine the value that actually gets used. (No value being equal to 1.)

this tag should be placed after the shields and hull values as it relies on them for calculation

Data keys shouldn't require a specific ordering to function. If one value needs information from another to work, that should be done in FinishLoading() functions.

@Amazinite
Copy link
Collaborator

It might also make sense to calculate the explosion damage on the fly when a ship explodes, should we want to concern ourselves with outfits that can increase/decrease the shields/hull of a ship.

@RisingLeaf
Copy link
Contributor Author

It might also make sense to calculate the explosion damage on the fly when a ship explodes, should we want to concern ourselves with outfits that can increase/decrease the shields/hull of a ship.

We did not until now, so I would leave that to another PR, if that's ok.

@Quantumshark
Copy link
Collaborator

I think it'd make sense to allow this token to have a decimal value next to it that can be used to scale the default explosion. So "auto explosion" 0.5 would take the specified formulas and multiply their outputs by 0.5 to determine the value that actually gets used. (No value being equal to 1.)

Blast radius is lower relative to damage for higher-tier ships, so it wouldn't be a simple case of applying the same scaling factor to all four values.

@RisingLeaf
Copy link
Contributor Author

I think it'd make sense to allow this token to have a decimal value next to it that can be used to scale the default explosion. So "auto explosion" 0.5 would take the specified formulas and multiply their outputs by 0.5 to determine the value that actually gets used. (No value being equal to 1.)

did that

Data keys shouldn't require a specific ordering to function. If one value needs information from another to work, that should be done in FinishLoading() functions.

and that

still need to test it

@RisingLeaf
Copy link
Contributor Author

I think it'd make sense to allow this token to have a decimal value next to it that can be used to scale the default explosion. So "auto explosion" 0.5 would take the specified formulas and multiply their outputs by 0.5 to determine the value that actually gets used. (No value being equal to 1.)

Blast radius is lower relative to damage for higher-tier ships, so it wouldn't be a simple case of applying the same scaling factor to all four values.

could we square the multiplier for blast radius or something like that?
because adding more values to the attribute would remove the desired simplicity

@RisingLeaf
Copy link
Contributor Author

It might also make sense to calculate the explosion damage on the fly when a ship explodes, should we want to concern ourselves with outfits that can increase/decrease the shields/hull of a ship.

If we would want to do so, the LoadExplosion in Weapon would also be helpful so it lays at least some groundwork.

@TomGoodIdea TomGoodIdea added the enhancement A suggestion for new content or functionality that requires code changes label May 18, 2024
@Amazinite
Copy link
Collaborator

Amazinite commented May 18, 2024

adding more values to the attribute would remove the desired simplicity

I think the simplicity comes in the fact that this node would be doing calculations for you rather than you needing to calculate what these values would be given a ship's hull and shields. That is, should we tweak the hull and shields of a ship, we don't then also need to tweak the explosion. So even if the node looked something like this, it would still be simpler to use:

"auto explosion" <global multiplier>
	"blast radius" <multiplier>
	"shield damage" <multiplier>
	"hull damage" <multiplier>
	"hit force" <multiplier>

@RisingLeaf
Copy link
Contributor Author

adding more values to the attribute would remove the desired simplicity

I think the simplicity comes in the fact that this node would be doing calculations for you rather than you needing to calculate what these values would be given a ship's hull and shields. That is, should we tweak the hull and shields of a ship, we don't then also need to tweak the explosion. So even if the node looked something like this, it would still be simpler to use:

"auto explosion" <global multiplier>
	"blast radius" <multiplier>
	"shield damage" <multiplier>
	"hull damage" <multiplier>
	"hit force" <multiplier>

this almost looks like something that should be moved into a struct?

@RisingLeaf
Copy link
Contributor Author

RisingLeaf commented May 18, 2024

also could this be moved out of the attributes section?
reason being that it has nothing to do with an outfit

@Amazinite
Copy link
Collaborator

Amazinite commented May 18, 2024

Given how this is set up, I think it does make more sense as a direct child of ship instead of attributes. weapon is only a child of attributes because attributes is actually an outfit node in disguise, which is able to have a weapon node. This new mechanic doesn't necessarily need to be in the same location as that weapon node, though.

@RisingLeaf
Copy link
Contributor Author

Given how this is set up, I think it does make more sense as a direct child of ship instead of attributes. weapon is only a child of attributes because attributes is actually an outfit node in disguise, which is able to have a weapon node. This new mechanic doesn't necessarily need to be in the same location as that weapon node, though.

implemented, will update description, still needs testing XD

source/Ship.cpp Outdated Show resolved Hide resolved
Co-authored-by: TomGoodIdea <108272452+TomGoodIdea@users.noreply.github.com>
source/Weapon.h Outdated
@@ -59,6 +59,8 @@ class Weapon {
public:
// Load from a "weapon" node, either in an outfit, a ship (explosion), or a hazard.
void LoadWeapon(const DataNode &node);
// Load attributes that represent a ship explosion.
void LoadExplosion(double blastRadius, double shieldDamage, double hullDamage, double hitForce);
Copy link
Contributor

Choose a reason for hiding this comment

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

LoadExplosion feels like an inappropriate name given that the method doesn't load the data from anything. It is given some values and it assigns some of its members those values.
I like SetExplosion more.

source/Ship.cpp Outdated Show resolved Hide resolved
source/Ship.cpp Outdated
@@ -601,6 +619,20 @@ void Ship::Load(const DataNode &node)
// loaded yet. So, wait until everything has been loaded, then call this.
void Ship::FinishLoading(bool isNewInstance)
{
// Automatically create an explosion for this ship if requested but
// only if the ship does not already have a defined explosion.
if(autoExplosion.baseMult > 0. && !baseAttributes.IsWeapon())
Copy link
Contributor

Choose a reason for hiding this comment

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

Put autoExplosion in an std::optional.

source/Ship.cpp Outdated Show resolved Hide resolved
RisingLeaf and others added 2 commits May 27, 2024 21:20
Co-authored-by: warp-core <warp-core@users.noreply.github.com>
Co-authored-by: warp-core <warp-core@users.noreply.github.com>
Copy link
Contributor Author

@RisingLeaf RisingLeaf left a comment

Choose a reason for hiding this comment

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

Trying to code via phone

source/Ship.cpp Show resolved Hide resolved
source/Ship.cpp Outdated Show resolved Hide resolved
source/Ship.h Outdated Show resolved Hide resolved
source/Weapon.cpp Outdated Show resolved Hide resolved
source/Weapon.h Outdated Show resolved Hide resolved
source/Ship.cpp Outdated Show resolved Hide resolved
source/Ship.cpp Outdated Show resolved Hide resolved
source/Ship.cpp Outdated Show resolved Hide resolved
source/Ship.cpp Outdated Show resolved Hide resolved
source/Ship.cpp Outdated Show resolved Hide resolved
source/Ship.cpp Outdated Show resolved Hide resolved
source/PlayerInfo.h Outdated Show resolved Hide resolved
@RisingLeaf
Copy link
Contributor Author

@warp-core i think I adressed your comments

source/Ship.cpp Outdated Show resolved Hide resolved
source/Weapon.h Outdated Show resolved Hide resolved
Comment on lines +628 to +629
// Automatically create an explosion for this ship if requested but
// only if the ship does not already have a defined explosion.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure that we to have logic for explosion hierarchy? I'm not sure if there's a use-case for overriding the automatic explosion, so just directly setting the explosion in Load would be nicer and make it so that not every ship needs to carry around a vestigial autoExplosion variable that's never used again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Amazinite requested so.

RisingLeaf and others added 3 commits May 29, 2024 18:31
Co-authored-by: Daniel <101683475+Koranir@users.noreply.github.com>
Co-authored-by: Daniel <101683475+Koranir@users.noreply.github.com>
@RisingLeaf
Copy link
Contributor Author

tested, seems to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A suggestion for new content or functionality that requires code changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants