Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3176 closed enhancement (fixed)

[PATCH] Show a different notification when livestock is attacked

Reported by: fcxSanya Owned by: leper
Priority: If Time Permits Milestone: Alpha 19
Component: UI & Simulation Keywords: gui simple patch
Cc: Itms Patch:

Description

Currently there is a generic "You have been attacked by %(attacker)s!" notification. It's a bit confusing to see it when an ally decides to gather player's livestock.

Attachments (8)

livestock_attack_notification_r16544.diff (2.1 KB ) - added by fcxSanya 9 years ago.
In this patch a different "Your livestock have been attacked by %(attacker)s!" notification is displayed if the attacked entity has the ResourceSupply component
add_template_name_into_attack_notificaiton_r16544.diff (2.0 KB ) - added by fcxSanya 9 years ago.
Alternative patch; displays the attacked entity's specific name in the notification, for example "Your Sheep have been attacked by %(attacker)s!", "Your Agorā́ have been attacked by %(attacker)s!"; this might be harder to translate to other languages
livestock_attack_notification_r16549.diff (2.2 KB ) - added by fcxSanya 9 years ago.
In this patch a different "Your livestock have been attacked by %(attacker)s!" notification is displayed if the attacked entity has the ResourceSupply component; this file differs from the previous version of the same patch by adding a code comment
add_generic_name_into_attack_notification_r16549.diff (2.0 KB ) - added by fcxSanya 9 years ago.
Alternative patch; displays the attacked entity's generic name in the notification, for example "Your Fauna have been attacked by %(attacker)s!", "Your Civic Center have been attacked by %(attacker)s!"; this might be harder to translate to other languages
no_attack_notification_for_domestic_animals_r16549.diff (2.1 KB ) - added by fcxSanya 9 years ago.
Another alternative patch; suspends the attack notification if the attacked entity has classes "Animal" and "Domestic"
no_attack_notification_for_domestic_animals_r16551.diff (962 bytes ) - added by fcxSanya 9 years ago.
Another alternative patch; suspends the attack notification if the attacked entity has classes "Animal" and "Domestic"; fixed version: the notification for domestic animals isn't sent in the first place
livestock_attack_notification_improved_suppression_r16572.diff (4.0 KB ) - added by fcxSanya 9 years ago.
In this patch a different "Your livestock have been attacked by %(attacker)s!" notification is displayed if the attacked entity has classes "Animal" and "Domestic"; if a non-livestock entity is attacked in the same area during the livestock notification suppression, the regular notification is still displayed
livestock_attack_notification_improved_suppression_r16653.diff (5.6 KB ) - added by fcxSanya 9 years ago.
New version of livestock_attack_notification_improved_suppression_r16572.diff​, updated according to leper's review in #comment:5

Download all attachments as: .zip

Change History (17)

by fcxSanya, 9 years ago

In this patch a different "Your livestock have been attacked by %(attacker)s!" notification is displayed if the attacked entity has the ResourceSupply component

by fcxSanya, 9 years ago

Alternative patch; displays the attacked entity's specific name in the notification, for example "Your Sheep have been attacked by %(attacker)s!", "Your Agorā́ have been attacked by %(attacker)s!"; this might be harder to translate to other languages

comment:1 by fcxSanya, 9 years ago

Summary: [PATCH] Show a different notificaiton when livestock is attacked[PATCH] Show a different notification when livestock is attacked

by fcxSanya, 9 years ago

In this patch a different "Your livestock have been attacked by %(attacker)s!" notification is displayed if the attacked entity has the ResourceSupply component; this file differs from the previous version of the same patch by adding a code comment

by fcxSanya, 9 years ago

Alternative patch; displays the attacked entity's generic name in the notification, for example "Your Fauna have been attacked by %(attacker)s!", "Your Civic Center have been attacked by %(attacker)s!"; this might be harder to translate to other languages

by fcxSanya, 9 years ago

Another alternative patch; suspends the attack notification if the attacked entity has classes "Animal" and "Domestic"

comment:2 by fcxSanya, 9 years ago

Hm, on second thought, in the third patch (no_attack_notification_for_domestic_animals_r16549.diff​) it's better to not send the notification from the AttackDetection component in the first place.

I still prefer the first patch though.

Last edited 9 years ago by fcxSanya (previous) (diff)

by fcxSanya, 9 years ago

Another alternative patch; suspends the attack notification if the attacked entity has classes "Animal" and "Domestic"; fixed version: the notification for domestic animals isn't sent in the first place

comment:3 by leper, 9 years ago

I prefer livestock_attack_notification_r16549.diff​, though an enemy attacking your livestock will have the benefit of being able to attack your other units/buildings in the same area without triggering another message.

by fcxSanya, 9 years ago

In this patch a different "Your livestock have been attacked by %(attacker)s!" notification is displayed if the attacked entity has classes "Animal" and "Domestic"; if a non-livestock entity is attacked in the same area during the livestock notification suppression, the regular notification is still displayed

in reply to:  3 comment:4 by fcxSanya, 9 years ago

Replying to leper:

I prefer livestock_attack_notification_r16549.diff​, though an enemy attacking your livestock will have the benefit of being able to attack your other units/buildings in the same area without triggering another message.

Should be fixed in livestock_attack_notification_improved_suppression_r16572.diff​, but at the cost of complicating the code a bit.

comment:5 by leper, 9 years ago

Cc: Itms added

var targetIsDomesticAnimal = cmpTargetIdentity && ..., else an entity without an Identity component (mods might do that, unlikely but possible) will throw errors.

event should use "" around property names.

Couldn't the first

for (var i = 0; i < this.suppressedList.length; i++) 
{ 
    var element = this.suppressedList[i];

be replaced with for (var element of this.suppressedList)? (or at least change i++ to ++i (also in the other loop below))

The assignment to element in the if seems broken, or at least not doing what it should (not an issue in your code, but since you're at it :-) ).

Is isPriorityIncreased actually needed? It seems just doing the break would be sufficient.

Also CCing Itms since he wrote that code IIRC.

comment:6 by Itms, 9 years ago

Why not removing the notification if it's livestock when the "attacker" is an ally? Enemies gathering from it would be considered as attackers, which sounds logical to me.

by fcxSanya, 9 years ago

New version of livestock_attack_notification_improved_suppression_r16572.diff​, updated according to leper's review in #comment:5

in reply to:  6 comment:7 by fcxSanya, 9 years ago

Replying to leper:

var targetIsDomesticAnimal = cmpTargetIdentity && ..., else an entity without an Identity component (mods might do that, unlikely but possible) will throw errors.

Fixed

event should use "" around property names.

Fixed

The assignment to element in the if seems broken, or at least not doing what it should

I replaced the assigment with UpdateSuppressionEvent(index, event) method, which updates suppressedList's element by index and creates a timer (like the existing AddSuppression(event) method)

Couldn't the first

for (var i = 0; i < this.suppressedList.length; i++) 
{ 
    var element = this.suppressedList[i];

be replaced with for (var element of this.suppressedList)?

With for...of loop it wouldn't be possible to replace element by index in the first loop (see above) and to use splice to remove element in the second one, right?

(or at least change i++ to ++i (also in the other loop below))

Done.

Is isPriorityIncreased actually needed? It seems just doing the break would be sufficient.

It's telling whether the event should be added into the suppressedList after the loop. Am I missing a simpler way to do this?


Replying to Itms:

Why not removing the notification if it's livestock when the "attacker" is an ally?

We can just remove it indeed, but since it provides somewhat useful information I prefer to preserve it if possible (but I won't be too disappointed if the consensus will be to get rid of it :))

comment:8 by leper, 9 years ago

Owner: set to leper
Resolution: fixed
Status: newclosed

In 16663:

Show a different notification if livestock is attacked. Patch by fcxSanya. Fixes #3176.

comment:9 by leper, 9 years ago

Keywords: review removed
Milestone: BacklogAlpha 19

Thanks for the patch.

I inlined a few system component calls, removed a useless event parameter for ActivateTimer, and made the loop use an early continue.

The code works quite nicely :-). I'll open another ticket about attack notifications when someone starts capturing your buildings.

Note: See TracTickets for help on using tickets.