#4193 closed defect (fixed)
[Patch] Loot tooltips
Reported by: | elexis | Owned by: | Mate-86 |
---|---|---|---|
Priority: | Must Have | Milestone: | Alpha 21 |
Component: | UI & Simulation | Keywords: | patch |
Cc: | fatherbushido | Patch: |
Description (last modified by )
Looting is a relatively unknown feature. In particular it is completely intransparent how many resources are earned when killing enemies or destroying buildings.
For example destroying a temple yields 500 metal! Killing a trade cart or a gathering unit yields the resources the unit carried.
The sum of these resources should be shown where all the other tooltips are shown, for every unit.
Attachments (19)
Change History (57)
comment:1 by , 8 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:2 by , 8 years ago
comment:3 by , 8 years ago
There is still an annoying thing (not so annoying). You ll not always see the loot you'll get (because some units can have a modified Looter: the loot you get depends of the plunder too).
by , 8 years ago
Attachment: | poc-techtree.png added |
---|
by , 8 years ago
Attachment: | poc-ingame.png added |
---|
by , 8 years ago
Attachment: | poc-multiple.png added |
---|
follow-up: 5 comment:4 by , 8 years ago
Attached proof of concept how the new field is displayed (with dummy values):
- in structure tree each unit and building has the base loot value (hardcoded in template) in the tooltip
- during the game each unit and building has an enhanced value (template + carried + traded + xp)
Questions: a; Shall I add the loot to the template or there is another ticket for that? => clarified, I need to check the template xml and not template.js b; Is the lootable XP a fix value and part of the template? Does it depends on the XP of the killed unit? => clarified: defined in loot.js and looter.js c; In which tooltip is the loot for multiple units displayed? In the attached 3rd poc the tooltip currently shows the name of the unit. => clarified: the sum of all units
comment:5 by , 8 years ago
Replying to Mate-86:
Questions: a; Shall I add the loot to the template or there is another ticket for that? => clarified, I need to check the template xml and not template.js
You'll need to add that to template.js and perhaps to GuiInterface.js (in the extended state part), take care to add it in the same way for the two files. (And to add it to GuiInterface tests.)
b; Is the lootable XP a fix value and part of the template? Does it depends on the XP of the killed unit? => clarified: defined in loot.js and looter.js
Defined in Loot. (Looter is for the entity wich will take the loot.)
comment:6 by , 8 years ago
Description: | modified (diff) |
---|
follow-up: 8 comment:7 by , 8 years ago
First version of the patch uploaded:
- Tech tree and multiple unit selection tooltips are enriched with looting information
- I need help for the single unit tool tip view: How to access entity information in getLootTooltip? Enity contains the resource carried by the worker. Currently the entity paramater gives back undefined. => elexis clarified I should add that calculation to Loot.js which is accessible though GuiInterface and template.js (but not mess up the behavior of Looter.js)
- I have to write the GuiInterface tests.
by , 8 years ago
Attachment: | 4193-loot-tooltip.patch added |
---|
by , 8 years ago
Attachment: | loot-techtree.png added |
---|
by , 8 years ago
Attachment: | loot-multiple.png added |
---|
by , 8 years ago
Attachment: | loot-single.png added |
---|
follow-up: 9 comment:8 by , 8 years ago
Replying to Mate-86:
First version of the patch uploaded:
- Tech tree and multiple unit selection tooltips are enriched with looting information
Thx for working on that. You decided to replace the carried ressources (in the gui) by the loot, that makes sense, ask elexis if he's ok with that.
- I need help for the single unit tool tip view: How to access entity information in getLootTooltip? Enity contains the resource carried by the worker. Currently the entity paramater gives back undefined. => elexis clarified I should add that calculation to Loot.js which is accessible though
GuiInterface
andtemplate.js
(but not mess up the behavior of Looter.js)
I m not fully convinced you should do that, it needs to be discussed. Perhaps you can then open a ticket suggesting this task.
- I have to write the
GuiInterface
tests.
You've just to add the stuff you added in GuiInterface
in the test (so that the object has all the keys).
tooltips.js
L579: template is the only param, isn't it ?selection_details
: you can usefor (let foo of arrayFoo)
(for arrays)
for (let i in lootTypes) { let type = lootTypes[i]; totalLoot[type] = (totalLoot[type] || 0) + extEntState.loot[type]; }
can be replaced by
for (let type of lootTypes) totalLoot[type] = (totalLoot[type] || 0) + extEntState.loot[type];
(wich can be perahps refined too)
and same above
selection_details
: you can perhaps (needs to be checked) add all when constructing the totalLoot object or something else.
comment:9 by , 8 years ago
Replying to fatherbushido:
Replying to Mate-86:
First version of the patch uploaded:
- Tech tree and multiple unit selection tooltips are enriched with looting information
Thx for working on that. You decided to replace the carried ressources (in the gui) by the loot, that makes sense, ask elexis if he's ok with that.
So how does the player knows how many resources his units are carrying?
comment:10 by , 8 years ago
Indeed, the tooltip shouldn't be replaced, but extended, like
Carrying: 123 food Loot: 234 food
comment:11 by , 8 years ago
@Mate-86: So you have your answer. And it's one more good reason to not move the computation to the Loot
component.
comment:12 by , 8 years ago
We discussed a bit more. L13-L42 would be code that is shared between gui/
and simulation/. Moving it to the
Loot component were bad, since that component doesn't use that code at all. Instead a function should be added to
globalscripts/`.
In order to merge duplicate code, it would have to receive an array of entityIDs (of units that are being looted/plundered) and optionally an attacker/looter entityID that if given, calls ApplyValueModificationsToEntity
(which is only available to simulation/
).
Notice #3934 will fix that TODO in the Looter code very soon.
by , 8 years ago
Attachment: | 4193-loot-tooltip.2.patch added |
---|
comment:13 by , 8 years ago
Issue fixed:
- Loot and carried res is displayed when multiple units selected
- "let type of lootTypes" applied
Issues remained:
- GuiInterface.js test updated but still fails (executed with Cygwin but still no info what is the issue)
- for a single unit only the hard-coded loot is displyed
- carried goods are displayed in another tooltip (mouseover the unit icon) for multiple units
- traded goods are not displayed separately in tooltip
Please advice which one I should fix or will be solved in another ticket!
comment:14 by , 8 years ago
I'm stuck. I've created the file LootHelper.js in globalscripts/ and copied there L13-L42 from Looter.js to eliminate code duplication. Now I get an error: "ReferenceError: IID_Loot is not defined". What to do?
by , 8 years ago
Attachment: | 4193-loot-tooltip.3.patch added |
---|
comment:17 by , 8 years ago
in fact you use sim methods outside of the sim. you have to write a function in wich you parse getcarriedressources and getgoods and getressources objects
comment:18 by , 8 years ago
Does this mean that I have to pass these objects as arguments to the calculator function in globalscripts/LootHelper.js instead of the looter and target entities ids?
by , 8 years ago
Attachment: | 4193-loot-tooltip.4.patch added |
---|
comment:20 by , 8 years ago
LootHelper updated based on the feedback from fatherbushido. Locally tested successfully.
comment:21 by , 8 years ago
Keywords: | rfc patch added |
---|---|
Milestone: | Backlog → Alpha 21 |
Summary: | Loot tooltips → [Patch] Loot tooltips |
comment:22 by , 8 years ago
nice!
In Templates.js
you can use perhaps for (let type in template.loot)
to skip that hardcoded loot types array (see costs in the same function).
Else there is your other work (siege in summary) in this patch.
by , 8 years ago
Attachment: | 4193-loot-tooltip.5.patch added |
---|
comment:23 by , 8 years ago
I've removed the siege related changes from the patch. I tried "for (let type in template.loot)" in template.js but it resulted "undefined property template.loot" error when I navigated to the techtree.
comment:24 by , 8 years ago
Thanks for your work! it seems we are close to the goal. Here are my review.
test_GuiInterface.js
:
- L18
add that:
Engine.LoadComponentScript("interfaces/Loot.js");
Template.js
:
- L252
remove L1 and replace
for (let type of lootTypes) if (template.Loot[type]) ret.loot[type] = getEntityValue("Loot/" + type);
by
for (let type in template.Loot) ret.loot[type] = getEntityValue("Loot/"+ type);
(no error here) (note for myself : perhaps, we should make all loot types mandatory)
selection_details.js
:
- L344 - 350
you would need to add that lootTypes array or instead (better) use a for (let type in objectFoo)
- At last, there are still broken stuff in the different tooltips. Iirc elexis asked:
- loot tooltip in the structure tree -> done
- loot tooltip in the individual unit tooltip taking account of ressources carried or goods traded (but not deleting those tooltips) -> seems broken
- loot tooltip in the multiple selections unit (same as previous) -> seems broken
-> Ask elexis some hints about that.
- Btw i got that error in a test game (only with the patch)
ERROR: Error in timer on entity 1, IID 57, function MissileHit: TypeError: carriedResources[Symbol.iterator] is not a function calculateResourcesCarried@globalscripts/LootHelper.js:10:1 Looter.prototype.Collect@simulation/components/Looter.js:21:25 Damage.prototype.TargetKilled@simulation/components/Damage.js:270:3 Damage.prototype.CauseDamage@simulation/components/Damage.js:224:3 Damage.prototype.MissileHit@simulation/components/Damage.js:126:1 Timer.prototype.OnUpdate@simulation/components/Timer.js:100:4
by , 8 years ago
Attachment: | commands.txt added |
---|
comment:25 by , 8 years ago
- loot tooltip in the multiple selections unit (same as previous) -> seems broken
works for me locally => http://i.imgur.com/wqsPgLk.png could you please post a screenshot?
- for the single unit Loot tooltip I need help because I cannot access entity information in gui/common/tooltip.js -> getLootTooltip() => @elexis could you give some hint please?
Taking care of the rest.
by , 8 years ago
Attachment: | 4193-loot-tooltip.6.patch added |
---|
comment:26 by , 8 years ago
Latest patch eliminates the problem about "TypeError: carriedResources[Symbol.iterator] is not a function" or at least I could not reproduce it with the attached replay anymore (before the fix I could reproduce it). I've added the lootTypes array to L344-350 in selection_details.js. For setting a "for (let type in objectFoo)" the keys of the objects should be merged which seems to be complicated. Eg. baseLoot of a unit is XP+food but it carries stone.
comment:27 by , 8 years ago
- your screenshot is ok,I have missed something
- for 2, what s your problem ? when getLootTooltip is called from selections details, the template arg is entState.
- after discussion it seems that the looterhelper new file is not really fully satisfacting. perhaps you can revert that, we would merge what is mergeable later in a better way.
by , 8 years ago
Attachment: | 4193-loot-tooltip.7.patch added |
---|
comment:29 by , 8 years ago
a, The single unit display issue fixed as well: http://i.imgur.com/z8R5eW1.png b, LooterHelper is used in 3 different places now:
- tooltips.js/getLootTooltip
- Looter.js
- selection_details.js/displayMultiple
Do you want me to copy the same code (calculateResourcesCarried) in all of these files? If you think it's less risky/nicer not to use the shared code of course I'll revert it. c, question: some of the resource types may have 0 value, shall I eliminate those from the tooltips? eg. stone/metal 0 here: http://i.imgur.com/wqsPgLk.png
comment:30 by , 8 years ago
a) nice b) ask elexis, he will decide (I have no strong opinion about that) c) perhaps it's simpler to let them, (or do like it's done for costs in selection_panels).
I will do my final review this evening.
comment:31 by , 8 years ago
- b) Three occurances?
getLootTooltip
doesn't have one. Well, as long as the exact same code is shared in both places and not having to be extended to 14 nested layers, avoiding the duplicate sounds preferable. - c) Yes, don't show the 0 entries. We don't show 0 entries anywhere so as to hide needless strings.
calculateResourcesCarried
should have some JSdoc style comment mentioning that the variables are either extendedEntityStates or- The name
calculateResourcesCarried
seems misleading as it doesn't imply that it implies trading goods. - Perhaps the
.goods
part can be moved tocalculateResourcesCarried
too (perhaps simplifying some of those ternaries.) - Not convinced to add a new file for 10 lines.
Templates.js
could be extended instead. calculateResourcesCarried
-> + should be at the end of the previous line. It's our coding convention (though missing in wiki:Coding_Conventions), and a common good practice, f.e. recommended by jshint.com.- Icon: File not found error for
art/textures/ui/session/icons/resources/xp_small.png
- Icon: If that icon from the screenshot is used, it should be transparent
translate("Carrying") + ": "
->sprintf(translate("Carrying: %(resources)s"), { "resources": foo }
, same for the other occurances of": "
(translators should be able to move that colon around. I guess the catch is that we need to colorize the label including the colon, which means"%(label)s%(colon)s %(value)s"
would have to be used. But don't do that as it's not the task of this ticket to rewrite all tooltips to fix that issue. You can use translate(Carrying:
) if you need that colorized colon, otherwise"Carrying: %(resources)s"
..length > 0
->.length
- Those "food", "wood",... will be rewritten following #3934, but that shouldn't be an issue now. (The objects will have to be constructed given a ["food", "wood", "metal", "stone"] array.)
- For the one committing the patch: New files added need the svn eol-style native property.
- Unused global
lootTypes
inTemplates.js
- Temples give 500 metal loot. Too much, wtf. Even a civic center gives onyl 50 wood 50 metal 50 stone. I suggest 50 metal for a temple and 250 wood metal stone for a civic center. Broken in r11524. Seems they were forgotton in nearly every new structure ever since. A probably complete list can be found in IRC. Fixing the templates would be a nice addition following the GUI patch!
- That what the diff said...
No newline at end of file
(as in files should end with newlines) LootHelper.js
L2 missing*
// TODO: stop assuming that cmpLoot.GetResources() delivers all resource types (by defining them in a central location)
removing that is wrong since you don't actually fix it.cmpLoot.GetResources
can just return an array with only one resource type.cmpResourceGatherer ? cmpResourceGatherer.GetCarryingStatus() : false,
could usefoo.bar() || false
instead I think- As pointed out by Imarok,
GetExtendedEntityState
already callsGetEntityState
(these proxy functions found insession.js
). So there is no point in doing theGetEntityState
call there at all. Should just replace it withExtended
. - (What I don't like about this comment is that many of these issues had been pointed out already.)
Patch looks ready to commit otherwise, good work.
by , 8 years ago
Attachment: | 4193-loot-tooltip.8.patch added |
---|
by , 8 years ago
by , 8 years ago
Attachment: | xp_small.png added |
---|
comment:32 by , 8 years ago
@elexis: thanks fot the comments!
- I've attached a new patch and the icons with transparent background to the ticket (xp.png and xp_small.png)
- "Temples give 500 metal loot. Too much ..." => is this something I should fix or just an info?
- the rest should be ok but plz let me know if I missed out something
comment:33 by , 8 years ago
Patch looking VERY good :) (few comments in irc today that are fixed with the next upload)
About the messed up templates, if you get this one committed, I'd be happy to fix this now too. If we present players those interesting loot values, they should be proper values ideally. From yesterdays IRC log:
10:41 fatherbushido: temple metal loot 500 -> 50, civic center 50 50 50 -> 250 250 250? 10:41 broken in r11524 11:03 I'd pick 250 as its half of the build cost 11:30 fatherbushido: persian temple got no loot component 11:30 persian hall 11:30 wonder could have slightly more 11:30 fort too :P 11:31 blacksmith less 11:32 ptol lighthouse missing Loot 11:32 library missing 11:33 roman army camp missing 11:34 temple of vesta should use relative templates, +50% or something 11:34 barracks could give slightly more loot 11:35 tower more loot too 11:35 military colony is ok 11:36 theatron missing loot 11:36 athen gymnaseon missing loot 11:36 royal stoa might be a bit more 11:39 kennel missing loot 11:45 fatherbushido: rotary mill should have loot too, by inheriting template_structure_economic rather than template_structure_special, no? 11:45 naval shipyard has no loot 11:46 monuments dont have it 11:46 siege workshop neither, surprise 11:46 elephant stables 11:46 persian gate 11:47 lighthouse if I didnt mention that already
For most buildings it makes sense to give them 10-30% loot value.
by , 8 years ago
Attachment: | 4193-loot-tooltip.9.patch added |
---|
comment:34 by , 8 years ago
Some more fixes uploaded. I could not eliminate the lootTypes array from tooltips.js/getLootTooltip because the keys returned by the template are sorted alphabetically (food, metal, ...) and 0 values are not filtered (xml templates contain 0 loot values too).
by , 8 years ago
Attachment: | 4193-loot-tooltip.10.patch added |
---|
comment:35 by , 8 years ago
I've introduced regression in patch 9 so that Looter.js fails. I've added some guards around cmpResourceGatherer (Looter.js L22) and trader.goods (Template.js L407). Should be fixed now.
comment:37 by , 8 years ago
Keywords: | simple rfc removed |
---|
Thanks for the patch Mate-86! You have very bravely addressed all remarks and made a very clean patch solving this issue quickly. Happy to see more contributions :)
As mentioned above, we should also fix the templates now that everyone can see these values. Besides the given list above, only military structures, perhaps the wonder should give experience point loot (since one doesn't really learn fighting skills when kicking over a storehouse).
Some changes I had done to your patch:
- Had asked for these JSdoc comments that we have an exact description of what our input is for
calculateResourcesAndGoodsCarried
. The descriptionthe looted trader
doesn't provide any useful information to the reader. Finding a better one revealed that the helper function accesses thegoods
variable of theTrader
prototype directly.goods
ought to be a local variable which can't be read or changed outside. Getter functions should be used for that (GetGoods
). F.e. the prototype might want to use a differnt variable name or apply some value modifications when returning the value. Changing the new function to just receive the carried goods, thus having an exact definition of input too. (Notice theentState.trader && entState.trader.goods
check is not needed, asGUIInterface.js
always provides the latter.) The fileTemplates.js
thus is also more legitimately extended, as the arguments follow theGetEntityState
format like the other functions of that file. foo > 0
should be replaced byfoo
checks, if foo is non-negative. similarfoo==0
should become!foo
(here: loot > 0)getLootTooltip
-> Merging those 2 loops: Unneeded variableloots
. Unneeded term(loots[type] || 0)
which will alwas be zero (since there is only 1 selected entity). Merging those:let templateLoot = 0; if (template.loot) templateLoot = template.loot[type] || 0;
MovinglootTypes
definition down a bit.- Renaming
totalResourcesAndGoodsCarried
tototalCarrying
resourcesAndGoodsCarried
tocarrying
calculateResourcesAndGoodsCarried
tocalculateCarriedResources
- Replacing
var
withlet
- Using
&&
in the Looter component, since that returns the second value if the first one is true - Removing
Loot
comment fromcalculateResourcesAndGoodsCarried
since that is also used to display the non-loot carrying resources tooltips - Removing two other unneeded comments (code became nice enough to read)
- Adding some spaces:
{"foo": "bar"}
->{ "foo": "bar" }
- Removed whitespace in emptylines and trailing whitespace.
showdetailedtooltips
is enabled)This way one can select a group of gathering units and see how much resources they are worth. This applies to observermode and players selecting their own units (since one can't select multiple enemy units currently).