Swim speed moddifiers

I was practicing coding by creating a few random mutations in a personal mod when I came across some trouble with modifying how well the player/avatar can move in the water. From what I understand, there isn’t an easy way to modify swim speed in the game: the mutation files don’t have variables in them that effect swim speed, instead each trait that does effect swim speed triggers a variable specific to that trait. (so a tail fin will effect encumbrance and clothing worn in the mutation file, but doesn’t have anything pertaining to swim speed.)
If you know how to add a flat modifier to a skill (like whiskers add to dodging), that would help as well.

Basically, I just want to know how to make a trait that makes you swim good. thank you for reading.

Look here https://github.com/CleverRaven/Cataclysm-DDA/blob/a39fc8374a839d1baae33e785dd08054ea10e03a/src/player.cpp#L743

Basically, its all hardcoded.

You could make a new trait, and then add the check in the c++ for that trait to add to swim speed.

2 Likes

I thought so, thank you.
EDIT: although how would you add the check? again, i’m practicing via mutations which kinda settle into the code on their own, would I have to copy the entire section in order to add the check, the swimming section, or what?

So say for exmple you add your own new mutation.

Then in that function you would add a check for something like. ( pseudocode )

`if( has_trait( trait_MY_NEW_MUTATION ) ) {
    ret -=  SOME_NUMBER
}`

or something.

and place it in the code near where the other traits are checked, basically it runs through lots of potential factors for swim speed, and changes the number ( ret ) for each thing.

Your new mutation woul djust be one more factor to check.

1 Like

Yeah, I mean would I have to copy a huge chunk of the code and place it in my mod folder in order to add the change or what?

ah no.

Theres two things happening here, one is in your mod folder, you add JSON stuff like new mutations, new items, new monsters etc.

Things that are modified in the c++ code need to be recompiled, so you would add those 3 lines to that specific file in that location the games source files.

you can then either a) recompile those changes to the C++ yourself, for your own personal use, you would need to read up on how to compile the game.

or b) submit your mod to the main repository and submit the required code changes to the main repository as pull requests. so that everyone else can use the mod.

It would probably be better if there was a swim_speed modifier to all mutations as a value, so all and any new mutations defined in JSON could modify it. Ill look into that.

1 Like

So basically OP would be a pioneer if he uses the second option, on a suggestion, could the trait he is making work as modifier for the swim skill?, like how dodge gest modified by encumbrance, like if the check confirms it has a trait like the tail, swim gets a bonus level.

1 Like

Well I had some free time, so I went ahead and coded in that option.

When that is merged, all OP will need to do for their new mutation is add something like :

"movecost_swim_modifier": 0.75, in the JSON for the mutation, and the code will do the rest now.

2 Likes

Thank you, hopefully I can learn to do things like this myself soon, as the lack of a variable to change is limiting at the moment. Giving the fact I only started modding a couple days ago, I’ll take it as a good thing that this was my first issue I needed direct help to get around.

but if you have an easy answer (probably not) how would you fiddle around with the game’s ‘photosynthetic’ traits? It’s a similar issue to the swim speed but with an actual excuse on why the variables are hidden from the common player: sensing light.
again, if you don’t have an easy answer, don’t worry about it, I just want to make traits like say, ‘Pine Needles’ give bonuses in sunlight.

Photosynthesis is currently the same.

it is hardcoded checks for specific mutations, instead of reading a variable.

Tomorrow I can look at jsonizing that variable too perhaps.

1 Like

Thank you, but at some point you have to leave me with something to learn from, lol.

Amazing, idk why but I never really looked into the c++ part of modding yet as I thought it would be a steep learning curve from my current knowledge about coding, but I completely understood every part of that file. I’m not so put off at the thought of making my mod now. Thanks for helping to open my eyes!! :exploding_head:

1 Like

That’s why enforcing coding style is important.

Javascript having linters is a life saver. Never have to think twice about how your code looks.