MegaGlest Forum

MegaGlest => Feature requests => Closed feature requests => Topic started by: MirceaKitsune on 25 March 2014, 20:38:47

Title: [done] Looting
Post by: MirceaKitsune on 25 March 2014, 20:38:47
I was surprised to hear this doesn't exist yet, since it's a rather basic feature and needed for many ideas. If it's not too difficult, please consider adding it soon!

I'd like a new function in the faction XML to specify a list of resources that destroying an unit will give the attacker. If a value is specified, that amount of the resource is given, whereas specifying a percentage gives that amount from what the faction which owns it has. If specifying a negative value, the attacker would actually lose that resource when destroying an enemy building, although that would make little sense. A flag should specify if to also deduct that amount from the owner faction and how much, or if to just make those resources appear to the attacker. If the attacking faction does not use the resource or have where to store it, there's no effect. The function I have in mind would be something like this:

Code: [Select]
<resources-death><resource name, amount, loss/></resources-death>
Example 1: A faction has a building which can be looted of half of the resources it was build with. It costs 100 gold and 50 stone to build. When it comes to the gold, the owning faction will also lose half of what's being looted. Also, 5% of the faction's entire wood stock will be taken away entirely. The code would be:

Code: [Select]
<resources-death>
<resource name="gold" amount="50" loss="50%"/>
<resource name="stone" amount="25" loss="0%"/>
<resource name="wood" amount="5%" loss="100%"/>
</resources-death>

Example 2: The attacking faction uses an unique resource called X, which is optional and can only be extracted by destroying a certain building from another faction. That faction however doesn't use the X resource in any way itself. Implicitly, the resource can only be obtained if the attacker is playing against this faction so they have the building to destroy. The victim faction's building would have this code:

Code: [Select]
<resources-death>
<resource name="X" amount="50" loss="0%"/>
</resources-death>

Before anyone asks, yes, I'm aware this is already possible in Lua for scenarios. To properly do it as part of a faction however, it must also be possible within the XML files of units, otherwise it will not be consistent and won't work in normal battles.
Title: Re: Looting
Post by: Omega on 25 March 2014, 22:15:49
Good idea. However, the use of percentage signs is very inconsistent with the rest of the XMLs. Rather, we should be using a probability (ie, a number between 0.0 and 1.0) to represent percentages.

To do so in a reasonable manner, we'd need an additional parameter. Probably separate parameters for absolute numbers vs percentages.

Eg,

Code: [Select]
<!-- Get 50 children's tears and the player who just lost their unit loses 50 -->
<resource name="children's_tears" amount="50" loss="50" />

<!-- Get 500% of the faction's stock of printer_ink, but they only actually lose 50% of their stock -->
<!-- If this was real life, you'd be a billionaire overnight. This stuff's like unicorn blood -->
<resource name="printer_ink" amount-percentage="5.0" loss-percentage="0.5" />

The last example is slightly different from your proposal. Instead of loss-percentage defining how much the opponent loses as a percentage of what we took, it defines how much the opponent loses as a percentage of their total. Thus, if we want to take 5% of the opponents resource and they lose all of that 5%, we'd simply set amount-percentage and loss-percentage both to be 0.05.
Title: Re: Looting
Post by: MirceaKitsune on 26 March 2014, 02:51:30
Makes sense. The percentages aren't a feature I care very much about, I only mentioned them because they might be helpful and I remember seeing them in other XML functions. The part I consider really important is adding an XML function to units so they can give the attacker which destroys them a certain amount of resources... allowing for looting or harvesting your enemies (sometimes for unique resources).
Title: Re: Looting
Post by: Ishmaru on 26 March 2014, 23:07:22
This would all a whole new level of depth to the game. It would be an exciting new feature to play with.
Title: Re: Looting
Post by: Omega on 19 July 2014, 23:11:20
Done! See the pull request for details (https://github.com/MegaGlest/megaglest-source/pull/17).

EDIT: Gah, I have some minor compilation errors that appear to be platform dependent (no errors in my build). I'll try and get these fixed, but it's gonna be a pain in the ass when I'm not getting the errors locally (TravisCI takes like 10 minutes to let me know if the build passed).

EDIT2: Fixed. Turns out Windows overrides a standard library function with a macro somewhere in its headers (which are presumably included by some library).
Title: Re: [Awaiting pull] Looting
Post by: MirceaKitsune on 19 July 2014, 23:27:21
Awesome! Thank you for adding this great feature... it will likely be a lot of fun :O
Title: Re: [Awaiting pull] Looting
Post by: Omega on 20 July 2014, 01:59:53
Titi, the "issue" of looting faction specific resources that I mentioned in the IRC is actually non-existent. There's no issues here. The resources are correctly ignored and are not displayed. It turns out I was modified the wrong part of the XML when editing it (creating a resource requirement instead). As far as I can tell, there's no issues with this change. I also played a full game to make sure that the AI wouldn't go wonky or anything.

As we discussed, all percentages are now integers (also applies to the starting HP/EP change). This is done in hopes of avoiding possible multiplayer out of sync errors caused by clients calculating floating point numbers in different ways.
Title: Re: [Awaiting pull] Looting
Post by: titi on 28 July 2014, 00:33:36
This is in develop branch now for some days, anyone tested this already ?

If you don't know how to compile for yourself, here you can find test binary/exe files http://snapshots.megaglest.org/ (http://snapshots.megaglest.org/)
Title: Re: [Done] Looting
Post by: Ishmaru on 2 August 2014, 18:36:36
This is in develop branch now for some days, anyone tested this already ?

If you don't know how to compile for yourself, here you can find test binary/exe files http://snapshots.megaglest.org/ (http://snapshots.megaglest.org/)

Will test asap!
Title: Re: [Done] Looting
Post by: titi on 19 May 2015, 08:59:35
Anyone tested this yet and is willing to add this in the Wiki ? ( the change was this: https://github.com/MegaGlest/megaglest-source/commit/082f3472ee2f4e58cd1379030dfacdafd5682e23)
and more Details here: https://github.com/MegaGlest/megaglest-source/pull/17
Title: Re: [Done: Test and Wiki needed] Looting
Post by: titi on 6 October 2015, 10:11:03
Its described in the wiki and tested now. ( thanks Jammy )
https://docs.megaglest.org/XML/Unit#resources-death_.28_looting_.29

https://forum.megaglest.org/index.php?topic=9740.msg92044#msg92044