Ticket #3176: livestock_attack_notification_improved_suppression_r16572.diff
File livestock_attack_notification_improved_suppression_r16572.diff, 4.0 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/session/messages.js
119 119 addChatMessage({ 120 120 "type": "attack", 121 121 "player": player, 122 "attacker": notification.attacker 122 "attacker": notification.attacker, 123 "targetIsDomesticAnimal": notification.targetIsDomesticAnimal 123 124 }); 124 125 }, 125 126 "dialog": function(notification, player) … … 509 510 return; 510 511 511 512 [username, playerColor] = getUsernameAndColor(msg.attacker); 512 formatted = sprintf(translate("You have been attacked by %(attacker)s!"), { attacker: "[color=\"" + playerColor + "\"]" + username + "[/color]" }); 513 // Since livestock can be attacked/gathered by allied players, 514 // we display a more specific notification in this case to not confuse the player 515 if (msg.targetIsDomesticAnimal) 516 var message = translate("Your livestock have been attacked by %(attacker)s!"); 517 else 518 var message = translate("You have been attacked by %(attacker)s!"); 519 formatted = sprintf(message, { attacker: "[color=\"" + playerColor + "\"]" + username + "[/color]" }); 513 520 break; 514 521 case "message": 515 522 // May have been hidden by the 'team' command. -
binaries/data/mods/public/simulation/components/AttackDetection.js
53 53 // Don't register attacks dealt by myself 54 54 if (cmpAttackerOwnership.GetOwner() == cmpPlayer.GetPlayerID()) 55 55 return; 56 57 // Since livestock can be attacked/gathered by allied players 58 // and generally not so valuable as other units/buildings, 59 // we have a lower priority notification for it, which can be 60 // later overriden by a regular one. 61 var cmpTargetIdentity = Engine.QueryInterface(target, IID_Identity); 62 var targetIsDomesticAnimal = cmpTargetIdentity.HasClass("Animal") && cmpTargetIdentity.HasClass("Domestic"); 56 63 57 64 var cmpPosition = Engine.QueryInterface(target, IID_Position); 58 65 if (!cmpPosition || !cmpPosition.IsInWorld()) 59 66 return; 60 67 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 61 var event = {target: target, position: cmpPosition.GetPosition(), time: cmpTimer.GetTime()}; 68 var event = { 69 target: target, 70 position: cmpPosition.GetPosition(), 71 time: cmpTimer.GetTime(), 72 targetIsDomesticAnimal: targetIsDomesticAnimal 73 }; 62 74 75 // If we already have a low priority livestock event in suppressed list, 76 // and now a more important target is attacked, we want to upgrade the 77 // suppressed event and send the new notification 78 var isPriorityIncreased = false; 63 79 for (var i = 0; i < this.suppressedList.length; i++) 64 80 { 65 81 var element = this.suppressedList[i]; … … 69 85 var dist = SquaredDistance(element.position, event.position); 70 86 if (dist < this.suppressionRangeSquared) 71 87 { 88 isPriorityIncreased = element.targetIsDomesticAnimal && !targetIsDomesticAnimal; 89 72 90 if (dist < this.suppressionTransferRangeSquared) 73 91 element = event; 92 93 if (isPriorityIncreased) 94 break; 95 74 96 return; 75 97 } 76 98 } 77 99 78 this.AddSuppression(event); 100 // If priority has increased for an existing event, then we already have it 101 // in the suppression list 102 if (!isPriorityIncreased) 103 this.AddSuppression(event); 79 104 Engine.PostMessage(this.entity, MT_AttackDetected, { "player": cmpPlayer.GetPlayerID(), "event": event }); 80 105 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 81 cmpGuiInterface.PushNotification({"type": "attack", "players": [cmpPlayer.GetPlayerID()], "attacker": cmpAttackerOwnership.GetOwner() }); 106 cmpGuiInterface.PushNotification({ 107 "type": "attack", 108 "players": [cmpPlayer.GetPlayerID()], 109 "attacker": cmpAttackerOwnership.GetOwner(), 110 "targetIsDomesticAnimal": targetIsDomesticAnimal 111 }); 82 112 PlaySound("attacked", target); 83 113 }; 84 114