Ticket #1719: AttackNotificationApr072013.patch
File AttackNotificationApr072013.patch, 15.7 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/messages.js
78 78 "amounts": notification.amounts 79 79 }); 80 80 } 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 } 81 88 else 82 89 { 83 90 // Only display notifications directed to this player … … 356 363 357 364 formatted = "[color=\"" + playerColor + "\"]" + username + "[/color] has sent you " + amounts + "."; 358 365 break; 366 case "attack": 367 if (msg.player != Engine.GetPlayerID()) 368 return; 369 370 formatted = "We're under attack!"; 371 break; 359 372 case "message": 360 373 // May have been hidden by the 'team' command. 361 374 if (msg.hide) -
binaries/data/mods/public/simulation/components/GuiInterface.js
620 620 return cmpBattleDetection.GetState(); 621 621 }; 622 622 623 // Returns a list of ongoing attacks against the player. 624 GuiInterface.prototype.GetIncomingAttacks = function(player) 625 { 626 var cmpAttackDetection = QueryPlayerIDInterface(player, IID_AttackDetection); 627 return cmpAttackDetection.GetIncomingAttacks(); 628 }; 629 623 630 // Used to show a red square over GUI elements you can't yet afford. 624 631 GuiInterface.prototype.GetNeededResources = function(player, amounts) 625 632 { … … 1720 1727 "CheckTechnologyRequirements": 1, 1721 1728 "GetStartedResearch": 1, 1722 1729 "GetBattleState": 1, 1730 "GetIncomingAttacks": 1, 1723 1731 "GetNeededResources": 1, 1724 1732 "GetNextNotification": 1, 1725 1733 -
binaries/data/mods/public/simulation/components/interfaces/AttackDetection.js
1 Engine.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. 9 Engine.RegisterMessageType("AttackDetected"); -
binaries/data/mods/public/simulation/templates/special/player.xml
12 12 <Player/> 13 13 <StatisticsTracker/> 14 14 <TechnologyManager/> 15 <AttackDetection/> 15 16 <BattleDetection> 16 17 <TimerInterval>200</TimerInterval> 17 18 <RecordLength>12</RecordLength> -
binaries/data/mods/public/simulation/templates/template_structure.xml
85 85 <select>interface/select/building/sel_universal.xml</select> 86 86 <constructed>interface/complete/building/complete_universal.xml</constructed> 87 87 <death>attack/destruction/building_collapse_large.xml</death> 88 <attacked>interface/alarm/alarm_attackplayer.xml</attacked> 88 89 </SoundGroups> 89 90 </Sound> 90 91 <StatusBars> -
binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml
79 79 <walk>actor/mounted/movement/walk.xml</walk> 80 80 <run>actor/mounted/movement/walk.xml</run> 81 81 <attack>attack/weapon/sword.xml</attack> 82 <attacked>interface/alarm/alarm_attackplayer.xml</attacked> 82 83 <death>actor/fauna/death/death_horse.xml</death> 83 84 <trained>interface/alarm/alarm_create_cav.xml</trained> 84 85 </SoundGroups> -
binaries/data/mods/public/simulation/templates/template_unit_champion.xml
14 14 <stone>0</stone> 15 15 <metal>20</metal> 16 16 </Loot> 17 <Sound> 18 <SoundGroups> 19 <attacked>interface/alarm/alarm_attackplayer.xml</attacked> 20 </SoundGroups> 21 </Sound> 17 22 </Entity> -
binaries/data/mods/public/simulation/templates/template_unit_hero.xml
60 60 <Sound> 61 61 <SoundGroups> 62 62 <attack>attack/weapon/sword.xml</attack> 63 <attacked>interface/alarm/alarm_attackplayer.xml</attacked> 63 64 <death>actor/human/death/death.xml</death> 64 65 </SoundGroups> 65 66 </Sound> -
binaries/data/mods/public/simulation/templates/template_unit_infantry.xml
92 92 <Sound> 93 93 <SoundGroups> 94 94 <select>voice/hellenes/civ/civ_male_select.xml</select> 95 <attacked>interface/alarm/alarm_attackplayer.xml</attacked> 95 96 <order_walk>voice/hellenes/civ/civ_male_ack.xml</order_walk> 96 97 <order_attack>voice/hellenes/civ/civ_male_attack.xml</order_attack> 97 98 <order_gather>voice/hellenes/civ/civ_male_ack.xml</order_gather> -
binaries/data/mods/public/simulation/templates/template_unit_mechanical.xml
21 21 <stone>0</stone> 22 22 <metal>25</metal> 23 23 </Loot> 24 <Sound> 25 <SoundGroups> 26 <attacked>interface/alarm/alarm_attackplayer.xml</attacked> 27 </SoundGroups> 28 </Sound> 24 29 </Entity> -
binaries/data/mods/public/simulation/templates/template_unit_support.xml
23 23 <Sound> 24 24 <SoundGroups> 25 25 <trained>interface/alarm/alarm_create_worker.xml</trained> 26 <attacked>interface/alarm/alarm_attackplayer.xml</attacked> 26 27 </SoundGroups> 27 28 </Sound> 28 29 <UnitAI> -
source/gui/MiniMap.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 69 69 m_ShallowPassageHeight = pathingSettings.GetChild("default").GetChild("MaxWaterDepth").ToFloat(); 70 70 else 71 71 m_ShallowPassageHeight = 0.0f; 72 73 m_ChangePingColor = 0; 72 74 } 73 75 74 76 CMiniMap::~CMiniMap() … … 469 471 v.a = 255; 470 472 v.x = posX.ToFloat()*sx; 471 473 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 472 500 vertexArray.push_back(v); 473 501 } 474 502 } 475 503 } 476 504 505 // Cycle the ping color counter as needed 506 m_ChangePingColor = (m_ChangePingColor + 1) > PING_DURATION ? 0 : (m_ChangePingColor + 1); 507 477 508 if (!vertexArray.empty()) 478 509 { 479 510 glEnableClientState(GL_VERTEX_ARRAY); … … 497 528 } 498 529 499 530 PROFILE_END("minimap units"); 500 531 501 532 if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER) 502 533 { 503 534 tech->EndPass(); -
source/gui/MiniMap.h
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 18 18 #ifndef INCLUDED_MINIMAP 19 19 #define INCLUDED_MINIMAP 20 20 21 // GUI 21 22 #include "gui/GUI.h" 22 23 24 // Types 25 #include "lib/types.h" 26 23 27 class CCamera; 24 28 class CTerrain; 25 29 30 // Pinging constants - Controls blink duration of the ping, smaller means higher 31 // ping frequency 32 const unsigned int PING_DURATION = 50; 33 26 34 class CMiniMap : public IGUIObject 27 35 { 28 36 GUI_OBJECT(CMiniMap) 29 37 public: 30 38 CMiniMap(); 31 39 virtual ~CMiniMap(); 40 32 41 protected: 33 42 virtual void Draw(); 34 43 … … 81 90 // maximal water height to allow the passage of a unit (for underwater shallows). 82 91 float m_ShallowPassageHeight; 83 92 93 // For tracking the ping color 94 u32 m_ChangePingColor; 95 84 96 void DrawTexture(float coordMax, float angle, float x, float y, float x2, float y2, float z); 85 97 86 98 void DrawViewRect(); -
source/simulation2/components/CCmpMinimap.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 25 25 #include "simulation2/MessageTypes.h" 26 26 27 27 #include "ps/Overlay.h" 28 #include "ps/Game.h" 28 29 29 30 class CCmpMinimap : public ICmpMinimap 30 31 { … … 33 34 { 34 35 componentManager.SubscribeToMessageType(MT_PositionChanged); 35 36 componentManager.SubscribeToMessageType(MT_OwnershipChanged); 37 componentManager.SubscribeToMessageType(MT_EntityAttacked); 36 38 } 37 39 38 40 DEFAULT_COMPONENT_ALLOCATOR(Minimap) … … 48 50 bool m_Active; 49 51 entity_pos_t m_X, m_Z; // cache the latest position for more efficient rendering; only valid when m_Active true 50 52 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 51 62 static std::string GetSchema() 52 63 { 53 64 return … … 82 93 virtual void Init(const CParamNode& paramNode) 83 94 { 84 95 m_Active = true; 96 m_PingEntity = false; 85 97 86 98 const CParamNode& colour = paramNode.GetChild("Colour"); 87 99 if (colour.IsOk()) … … 183 195 184 196 break; 185 197 } 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; 186 213 } 214 } 187 215 } 188 216 189 217 virtual bool GetRenderData(u8& r, u8& g, u8& b, entity_pos_t& x, entity_pos_t& z) … … 198 226 z = m_Z; 199 227 return true; 200 228 } 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 } 201 250 }; 202 251 203 252 REGISTER_COMPONENT_TYPE(Minimap) -
source/simulation2/components/ICmpMinimap.h
35 35 */ 36 36 virtual bool GetRenderData(u8& r, u8& g, u8& b, entity_pos_t& x, entity_pos_t& z) = 0; 37 37 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 38 53 DECLARE_INTERFACE_TYPE(Minimap) 39 54 }; 40 55 -
source/simulation2/MessageTypes.h
398 398 entity_pos_t newRange; 399 399 }; 400 400 401 /** 402 * Sent when an entity is attacked 403 */ 404 class CMessageEntityAttacked : public CMessage 405 { 406 public: 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 401 418 #endif // INCLUDED_MESSAGETYPES -
source/simulation2/scripting/MessageTypeConversions.cpp
336 336 return new CMessageVisionRangeChanged(entity, oldRange, newRange); 337 337 } 338 338 339 //////////////////////////////// 340 341 jsval 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 349 CMessage* 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 339 357 //////////////////////////////////////////////////////////////// 340 358 341 359 CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, jsval val) -
source/simulation2/TypeList.h
49 49 MESSAGE(PathResult) 50 50 MESSAGE(TechnologyModification) 51 51 MESSAGE(VisionRangeChanged) 52 MESSAGE(EntityAttacked) 52 53 53 54 // TemplateManager must come before all other (non-test) components, 54 55 // so that it is the first to be (de)serialized