Wargus / stratagus

The Stratagus strategy game engine
GNU General Public License v2.0
626 stars 120 forks source link

Documentation typo/incorrect information? #445

Open Kaitrei opened 1 year ago

Kaitrei commented 1 year ago

I believe I have found a typo in the documentation when trying to make a specific research increase the production cost of a unit and possibly something that was rewritten at some point in a way that is different from how it is documented.

I've attempted to figure out where the typo is by attempting the following in my upgrade.lua script: {"cost", ("metal", 50}}, yields [string "scripts/human/upgrade.lua"]:125: ')' expected near ',' {"cost", ("metal", 50)}, yields [string "scripts/human/upgrade.lua"]:125: ')' expected near ',' {"cost", "metal", 50}, yields incorrect argument {"cost", {"metal", 50}}, yields Resource not found: cost

I'm unable to figure out the correct way to use this tag. I had hoped to figure this out myself and then update the documentation lines, but it seems I can't figure out how it works.

Lines in documentation describing the cost tag on research: https://github.com/Wargus/stratagus/blob/8720f1fbb0f74296076e312d3c30a2084707add6/doc/scripts/research.html#L222C1-L224C45

SimoneStarace commented 1 year ago

I believe I have found a typo in the documentation when trying to make a specific research increase the production cost of a unit and possibly something that was rewritten at some point in a way that is different from how it is documented. Lines in documentation describing the cost tag on research: https://github.com/Wargus/stratagus/blob/8720f1fbb0f74296076e312d3c30a2084707add6/doc/scripts/research.html#L222C1-L224C45

Consider that documentation hasn't being updated for 7 years it is possible to find some typos but regarding this

I've attempted to figure out where the typo is by attempting the following in my upgrade.lua script: {"cost", ("metal", 50}}, yields [string "scripts/human/upgrade.lua"]:125: ')' expected near ',' {"cost", ("metal", 50)}, yields [string "scripts/human/upgrade.lua"]:125: ')' expected near ',' {"cost", "metal", 50}, yields incorrect argument {"cost", {"metal", 50}}, yields Resource not found: cost

From what I understand, you're trying to make an upgrade that costs X metal. I believe that metal is one of the resources already defined in the engine but if you want to make an upgrade to have that cost you can take a look on how upgrades are defined in Wargus.

Kaitrei commented 1 year ago

That is not what I am attempting to do. I am trying to make it so the upgrade increases the production cost of the units that benefit from the upgrade (this is meant to be a more significant upgrade that comes with drawbacks.)

Unfortunately, the documentation appears to show an incorrect way of formatting that scripting and there doesn't appear to be a right way at the moment. Unfortunately, my attempts at digging through the scripting system in Stratagus only confused me further as it appears that it's referencing a separate function to retrieve a resource ID that isn't working or expecting it formatted that way.

Unfortunately, I lost my notes on what I had found or I would post them here.

SimoneStarace commented 1 year ago

I am trying to make it so the upgrade increases the production cost of the units that benefit from the upgrade (this is meant to be a more significant upgrade that comes with drawbacks.)

One way to do this is, after the upgrade is completed, the unit affected from this will be transformed into another unit, similar on how WarCraft II does with Knights to Paladins and Ogres to Ogre-Magi.

What I'm trying to say is that you have to define a new unit type that has the same sprites, buttons, stats etc, but with the increased cost on the resource.

Unfortunately, the documentation appears to show an incorrect way of formatting that scripting and there doesn't appear to be a right way at the moment.

As I have already wrote yesterday, that documentation is old and it isn't updated for 7 years.

my attempts at digging through the scripting system in Stratagus only confused me further as it appears that it's referencing a separate function to retrieve a resource ID that isn't working or expecting it formatted that way.

To me, the function you're searching is called CclDefineModifier and the lines about changing the cost of a unit type are defined here. https://github.com/Wargus/stratagus/blob/8720f1fbb0f74296076e312d3c30a2084707add6/src/unit/upgrade.cpp#L290-L296

Kaitrei commented 1 year ago

The problem with doing that is that there will be more than one of these upgrades. I don't know if I can, or want to, make a new unit for every combination of these late game cost modifying upgrades. I was even considering making it so every level of the upgrade has a slight production cost increase.

The question is, how is this cost upgrade suppose to be formatting in the script? Or is it broken?

timfel commented 1 year ago

Your last code is correct. I don't know why you get unknown resource cost, the C++ code should be looking at the "metal" string, so there's a bug somewhere. Doing it via new units is a bit annoying, yes. One thing, you don't have to define two units, you can use CopyUnitType and then use DefineUnitStats to change the costs. But yes, a bit annoying if you have many combinations of upgrades that each affect the costs differently. Maybe @jarod42 will have a minute to check why the piece of code that @SimoneStarace linked doesn't work, because to my eyes it should. I just don't even have a dev environment for stratagus set up anymore, so I can't quickly jump in and debug

Kaitrei commented 1 year ago

Okay. I'll leave it as the last one, but commented out, and wait for an update on this.

Just as a sanity check, I did try changing out the resource for a few others in my project to see if it was having trouble looking up metal for some reason and it made no difference.

I lost my notes on looking through the LUA scripting, but if I remember correctly, it's looking up the resource using a different function that other parts of the engine use to look up a resource ID.

Going off the results in stderr.txt, it looks like it's trying to pass the word "cost" to the resource lookup function instead of the resource name.