Ticket #1719: AttackNotificationApr072013.patch

File AttackNotificationApr072013.patch, 15.7 KB (added by madmax, 11 years ago)

New Patch file

  • binaries/data/mods/public/gui/session/messages.js

     
    7878            "amounts": notification.amounts
    7979        });
    8080    }
     81    else if (notification.type == "attack")
     82    {
     83        if (notification.player == Engine.GetPlayerID())
     84        {
     85            Engine.GuiInterfaceCall("PlaySound", { "name":"attacked", "entity": notification.message.target });
     86        }
     87    }
    8188    else
    8289    {
    8390        // Only display notifications directed to this player
     
    356363
    357364        formatted = "[color=\"" + playerColor + "\"]" + username + "[/color] has sent you " + amounts + ".";
    358365        break;
     366    case "attack":
     367        if (msg.player != Engine.GetPlayerID())
     368            return;
     369
     370        formatted = "We're under attack!";
     371        break;
    359372    case "message":
    360373        // May have been hidden by the 'team' command.
    361374        if (msg.hide)
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    620620    return cmpBattleDetection.GetState();
    621621};
    622622
     623// Returns a list of ongoing attacks against the player.
     624GuiInterface.prototype.GetIncomingAttacks = function(player)
     625{
     626    var cmpAttackDetection = QueryPlayerIDInterface(player, IID_AttackDetection);
     627    return cmpAttackDetection.GetIncomingAttacks();
     628};
     629
    623630// Used to show a red square over GUI elements you can't yet afford.
    624631GuiInterface.prototype.GetNeededResources = function(player, amounts)
    625632{
     
    17201727    "CheckTechnologyRequirements": 1,
    17211728    "GetStartedResearch": 1,
    17221729    "GetBattleState": 1,
     1730    "GetIncomingAttacks": 1,
    17231731    "GetNeededResources": 1,
    17241732    "GetNextNotification": 1,
    17251733
  • binaries/data/mods/public/simulation/components/interfaces/AttackDetection.js

     
     1Engine.RegisterInterface("AttackDetection");
     2
     3// Message of the form { "target": 123, "x": 123, "z": 456, "time": 1 }.
     4// sent when an entity is attacked.
     5//Engine.RegisterMessageType("EntityAttacked");
     6
     7// Message of the form { "player": 1, "event": { "target": 123 , "position": { "x": 123, "z": 456 }, "time": 1, }.
     8// sent when a new attack is detected.
     9Engine.RegisterMessageType("AttackDetected");
  • binaries/data/mods/public/simulation/templates/special/player.xml

     
    1212  <Player/>
    1313  <StatisticsTracker/>
    1414  <TechnologyManager/>
     15  <AttackDetection/>
    1516  <BattleDetection>
    1617    <TimerInterval>200</TimerInterval>
    1718    <RecordLength>12</RecordLength>
  • binaries/data/mods/public/simulation/templates/template_structure.xml

     
    8585      <select>interface/select/building/sel_universal.xml</select>
    8686      <constructed>interface/complete/building/complete_universal.xml</constructed>
    8787      <death>attack/destruction/building_collapse_large.xml</death>
     88      <attacked>interface/alarm/alarm_attackplayer.xml</attacked>   
    8889    </SoundGroups>
    8990  </Sound>
    9091  <StatusBars>
  • binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml

     
    7979      <walk>actor/mounted/movement/walk.xml</walk>
    8080      <run>actor/mounted/movement/walk.xml</run>
    8181      <attack>attack/weapon/sword.xml</attack>
     82      <attacked>interface/alarm/alarm_attackplayer.xml</attacked>
    8283      <death>actor/fauna/death/death_horse.xml</death>
    8384      <trained>interface/alarm/alarm_create_cav.xml</trained>
    8485    </SoundGroups>
  • binaries/data/mods/public/simulation/templates/template_unit_champion.xml

     
    1414    <stone>0</stone>
    1515    <metal>20</metal>
    1616  </Loot>
     17  <Sound>
     18    <SoundGroups>
     19      <attacked>interface/alarm/alarm_attackplayer.xml</attacked>
     20    </SoundGroups>
     21  </Sound>
    1722</Entity>
  • binaries/data/mods/public/simulation/templates/template_unit_hero.xml

     
    6060  <Sound>
    6161    <SoundGroups>
    6262      <attack>attack/weapon/sword.xml</attack>
     63      <attacked>interface/alarm/alarm_attackplayer.xml</attacked>
    6364      <death>actor/human/death/death.xml</death>
    6465    </SoundGroups>
    6566  </Sound>
  • binaries/data/mods/public/simulation/templates/template_unit_infantry.xml

     
    9292  <Sound>
    9393    <SoundGroups>
    9494      <select>voice/hellenes/civ/civ_male_select.xml</select>
     95      <attacked>interface/alarm/alarm_attackplayer.xml</attacked>
    9596      <order_walk>voice/hellenes/civ/civ_male_ack.xml</order_walk>
    9697      <order_attack>voice/hellenes/civ/civ_male_attack.xml</order_attack>
    9798      <order_gather>voice/hellenes/civ/civ_male_ack.xml</order_gather>
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical.xml

     
    2121    <stone>0</stone>
    2222    <metal>25</metal>
    2323  </Loot>
     24  <Sound>
     25    <SoundGroups>
     26      <attacked>interface/alarm/alarm_attackplayer.xml</attacked>
     27    </SoundGroups>
     28  </Sound>
    2429</Entity>
  • binaries/data/mods/public/simulation/templates/template_unit_support.xml

     
    2323  <Sound>
    2424    <SoundGroups>
    2525      <trained>interface/alarm/alarm_create_worker.xml</trained>
     26      <attacked>interface/alarm/alarm_attackplayer.xml</attacked>
    2627    </SoundGroups>
    2728  </Sound>
    2829  <UnitAI>
  • source/gui/MiniMap.cpp

     
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2013 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    6969        m_ShallowPassageHeight = pathingSettings.GetChild("default").GetChild("MaxWaterDepth").ToFloat();
    7070    else
    7171        m_ShallowPassageHeight = 0.0f;
     72
     73    m_ChangePingColor = 0;
    7274}
    7375
    7476CMiniMap::~CMiniMap()
     
    469471                v.a = 255;
    470472                v.x = posX.ToFloat()*sx;
    471473                v.y = -posZ.ToFloat()*sy;
     474
     475                // Check minimap pinging to indicate something
     476                if (cmpMinimap->IsEntityPinging()) {
     477
     478                    // Override the normal rendering of the entity with the ping color
     479                    // Note: If the pinged entity's dot is rendered over by another entity's
     480                    // dot then it will be invisible & the ping will be not be seen.
     481                    // We can try to move the pinged dots towards the end in the vertexArray
     482                    // Keep 2 pointers and insert pinged dots at end, unpinged at current position
     483                    if (m_ChangePingColor > PING_DURATION/2) {
     484                        v.r = 255; // bright red
     485                        v.g = 1;
     486                        v.b = 1;
     487                    }
     488
     489                    // Must reduce ping count every frame
     490                    u32 pingCount = cmpMinimap->GetRemainingPingCount();
     491                    if (pingCount <= 0) {
     492                        // Also turns off ping flag if 0 passed in
     493                        cmpMinimap->SetRemainingPingCount(0);
     494                    }
     495                    else {
     496                        cmpMinimap->SetRemainingPingCount(pingCount - 1);
     497                    }
     498                }
     499
    472500                vertexArray.push_back(v);
    473501            }
    474502        }
    475503    }
    476504
     505    // Cycle the ping color counter as needed
     506    m_ChangePingColor = (m_ChangePingColor + 1) > PING_DURATION ? 0 : (m_ChangePingColor + 1);
     507
    477508    if (!vertexArray.empty())
    478509    {
    479510        glEnableClientState(GL_VERTEX_ARRAY);
     
    497528    }
    498529
    499530    PROFILE_END("minimap units");
    500    
     531
    501532    if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
    502533    {
    503534        tech->EndPass();
  • source/gui/MiniMap.h

     
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2013 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1818#ifndef INCLUDED_MINIMAP
    1919#define INCLUDED_MINIMAP
    2020
     21// GUI
    2122#include "gui/GUI.h"
    2223
     24// Types
     25#include "lib/types.h"
     26
    2327class CCamera;
    2428class CTerrain;
    2529
     30// Pinging constants - Controls blink duration of the ping, smaller means higher
     31// ping frequency
     32const unsigned int PING_DURATION = 50;
     33
    2634class CMiniMap : public IGUIObject
    2735{
    2836    GUI_OBJECT(CMiniMap)
    2937public:
    3038    CMiniMap();
    3139    virtual ~CMiniMap();
     40
    3241protected:
    3342    virtual void Draw();
    3443
     
    8190    // maximal water height to allow the passage of a unit (for underwater shallows).
    8291    float m_ShallowPassageHeight;
    8392
     93    // For tracking the ping color
     94    u32 m_ChangePingColor;
     95
    8496    void DrawTexture(float coordMax, float angle, float x, float y, float x2, float y2, float z);
    8597
    8698    void DrawViewRect();
  • source/simulation2/components/CCmpMinimap.cpp

     
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2013 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2525#include "simulation2/MessageTypes.h"
    2626
    2727#include "ps/Overlay.h"
     28#include "ps/Game.h"
    2829
    2930class CCmpMinimap : public ICmpMinimap
    3031{
     
    3334    {
    3435        componentManager.SubscribeToMessageType(MT_PositionChanged);
    3536        componentManager.SubscribeToMessageType(MT_OwnershipChanged);
     37        componentManager.SubscribeToMessageType(MT_EntityAttacked);
    3638    }
    3739
    3840    DEFAULT_COMPONENT_ALLOCATOR(Minimap)
     
    4850    bool m_Active;
    4951    entity_pos_t m_X, m_Z; // cache the latest position for more efficient rendering; only valid when m_Active true
    5052
     53
     54    // Used by the minimap while pinging this entity to indicate something(currently an attack)
     55    // Entity not pinged after MAX_PING_TURNS if it wasn't notified in between
     56    static const u32 MAX_PING_FRAMES = 500;
     57    bool m_PingEntity;
     58    u32 m_PingCount;
     59
     60
     61
    5162    static std::string GetSchema()
    5263    {
    5364        return
     
    8293    virtual void Init(const CParamNode& paramNode)
    8394    {
    8495        m_Active = true;
     96        m_PingEntity = false;
    8597
    8698        const CParamNode& colour = paramNode.GetChild("Colour");
    8799        if (colour.IsOk())
     
    183195
    184196            break;
    185197        }
     198        case MT_EntityAttacked:
     199        {
     200            const CMessageEntityAttacked& data = static_cast<const CMessageEntityAttacked&> (msg);
     201
     202            if (!g_Game)
     203                break;
     204
     205            if(g_Game->GetPlayerID() != (int)data.player)
     206                break;
     207
     208            m_Active = true;
     209            m_PingEntity = true;
     210            m_PingCount = MAX_PING_FRAMES;
     211
     212            break;
    186213        }
     214        }
    187215    }
    188216
    189217    virtual bool GetRenderData(u8& r, u8& g, u8& b, entity_pos_t& x, entity_pos_t& z)
     
    198226        z = m_Z;
    199227        return true;
    200228    }
     229
     230    virtual bool IsEntityPinging(void)
     231    {
     232        if (!m_Active)
     233            return false;
     234
     235        return m_PingEntity;
     236    }
     237
     238    virtual u32 GetRemainingPingCount(void)
     239    {
     240        return m_PingCount;
     241    }
     242
     243    virtual void SetRemainingPingCount(u32 pingCount)
     244    {
     245        m_PingCount = pingCount;
     246
     247        if (m_PingCount == 0)
     248            m_PingEntity = false;
     249    }
    201250};
    202251
    203252REGISTER_COMPONENT_TYPE(Minimap)
  • source/simulation2/components/ICmpMinimap.h

     
    3535     */
    3636    virtual bool GetRenderData(u8& r, u8& g, u8& b, entity_pos_t& x, entity_pos_t& z) = 0;
    3737
     38    /**
     39     * Returns true if the unit is pinging.
     40     */
     41    virtual bool IsEntityPinging(void) = 0;
     42
     43    /**
     44     * Returns the current ping count.
     45     */
     46    virtual u32 GetRemainingPingCount(void) = 0;
     47
     48    /**
     49     * Used by the minimap to set the ping count, controls pinging.
     50     */
     51    virtual void SetRemainingPingCount(u32 pingCount) = 0;
     52
    3853    DECLARE_INTERFACE_TYPE(Minimap)
    3954};
    4055
  • source/simulation2/MessageTypes.h

     
    398398    entity_pos_t newRange;
    399399};
    400400
     401/**
     402 * Sent when an entity is attacked
     403 */
     404class CMessageEntityAttacked : public CMessage
     405{
     406public:
     407    DEFAULT_MESSAGE_IMPL(EntityAttacked)
     408
     409    CMessageEntityAttacked(entity_id_t entity, entity_id_t player) :
     410    entity(entity), player(player)
     411    {
     412    }
     413
     414    entity_id_t entity;
     415    entity_id_t player;
     416};
     417
    401418#endif // INCLUDED_MESSAGETYPES
  • source/simulation2/scripting/MessageTypeConversions.cpp

     
    336336    return new CMessageVisionRangeChanged(entity, oldRange, newRange);
    337337}
    338338
     339////////////////////////////////
     340
     341jsval CMessageEntityAttacked::ToJSVal(ScriptInterface& scriptInterface) const
     342{
     343    TOJSVAL_SETUP();
     344    SET_MSG_PROPERTY(entity);
     345    SET_MSG_PROPERTY(player);
     346    return OBJECT_TO_JSVAL(obj);
     347}
     348
     349CMessage* CMessageEntityAttacked::FromJSVal(ScriptInterface& scriptInterface, jsval val)
     350{
     351    FROMJSVAL_SETUP();
     352    GET_MSG_PROPERTY(entity_id_t, entity);
     353    GET_MSG_PROPERTY(entity_id_t, player);
     354    return new CMessageEntityAttacked(entity, player);
     355}
     356
    339357////////////////////////////////////////////////////////////////
    340358
    341359CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, jsval val)
  • source/simulation2/TypeList.h

     
    4949MESSAGE(PathResult)
    5050MESSAGE(TechnologyModification)
    5151MESSAGE(VisionRangeChanged)
     52MESSAGE(EntityAttacked)
    5253
    5354// TemplateManager must come before all other (non-test) components,
    5455// so that it is the first to be (de)serialized