1
0
forked from 0ad/0ad

Show status-bars of all players to observers, fixes #3215.

This was SVN commit r17623.
This commit is contained in:
elexis 2016-01-10 16:47:57 +00:00
parent 8859f33b38
commit 8c7b6dceaa
6 changed files with 45 additions and 5 deletions

View File

@ -837,7 +837,7 @@ function recalculateStatusBarDisplay()
{
let entities;
if (g_ShowAllStatusBars)
entities = Engine.PickPlayerEntitiesOnScreen(Engine.GetPlayerID());
entities = Engine.GetPlayerID() == -1 ? Engine.PickNonGaiaEntitiesOnScreen() : Engine.PickPlayerEntitiesOnScreen(Engine.GetPlayerID());
else
{
let selected = g_Selection.toList();
@ -845,7 +845,7 @@ function recalculateStatusBarDisplay()
selected.push(g_Selection.highlighted[ent]);
// Remove selected entities from the 'all entities' array, to avoid disabling their status bars.
entities = Engine.GuiInterfaceCall("GetPlayerEntities").filter(idx => selected.indexOf(idx) == -1);
entities = Engine.GuiInterfaceCall(Engine.GetPlayerID() == -1 ? "GetNonGaiaEntities" : "GetPlayerEntities").filter(idx => selected.indexOf(idx) == -1);
}
Engine.GuiInterfaceCall("SetStatusBars", { "entities": entities, "enabled": g_ShowAllStatusBars });

View File

@ -860,6 +860,11 @@ GuiInterface.prototype.GetPlayerEntities = function(player)
return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetEntitiesByPlayer(player);
};
GuiInterface.prototype.GetNonGaiaEntities = function()
{
return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetNonGaiaEntities();
};
/**
* Displays the rally points of a given list of entities (carried in cmd.entities).
*
@ -1854,6 +1859,7 @@ let exposedFunctions = {
"GetAllBuildableEntities": 1,
"SetStatusBars": 1,
"GetPlayerEntities": 1,
"GetNonGaiaEntities": 1,
"DisplayRallyPoint": 1,
"SetBuildingPlacementPreview": 1,
"SetWallPlacementPreview": 1,

View File

@ -62,6 +62,7 @@
#include "simulation2/components/ICmpAIManager.h"
#include "simulation2/components/ICmpCommandQueue.h"
#include "simulation2/components/ICmpGuiInterface.h"
#include "simulation2/components/ICmpPlayerManager.h"
#include "simulation2/components/ICmpRangeManager.h"
#include "simulation2/components/ICmpSelectable.h"
#include "simulation2/components/ICmpTemplateManager.h"
@ -164,6 +165,24 @@ std::vector<entity_id_t> PickPlayerEntitiesOnScreen(ScriptInterface::CxPrivate*
return PickPlayerEntitiesInRect(pCxPrivate, 0, 0, g_xres, g_yres, player);
}
std::vector<entity_id_t> PickNonGaiaEntitiesOnScreen(ScriptInterface::CxPrivate* pCxPrivate)
{
std::vector<entity_id_t> entities;
CmpPtr<ICmpPlayerManager> cmpPlayerManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
if (!cmpPlayerManager)
return entities;
i32 numPlayers = cmpPlayerManager->GetNumPlayers();
for (i32 player = 1; player < numPlayers; ++player)
{
std::vector<entity_id_t> ents = PickPlayerEntitiesOnScreen(pCxPrivate, player);
entities.insert(entities.end(), ents.begin(), ents.end());
}
return entities;
}
std::vector<entity_id_t> PickSimilarPlayerEntities(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string templateName, bool includeOffScreen, bool matchRank, bool allowFoundations)
{
return EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, g_Game->GetPlayerID(), includeOffScreen, matchRank, false, allowFoundations);
@ -967,6 +986,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction<entity_id_t, int, int, &PickEntityAtPoint>("PickEntityAtPoint");
scriptInterface.RegisterFunction<std::vector<entity_id_t>, int, int, int, int, int, &PickPlayerEntitiesInRect>("PickPlayerEntitiesInRect");
scriptInterface.RegisterFunction<std::vector<entity_id_t>, int, &PickPlayerEntitiesOnScreen>("PickPlayerEntitiesOnScreen");
scriptInterface.RegisterFunction<std::vector<entity_id_t>, &PickNonGaiaEntitiesOnScreen>("PickNonGaiaEntitiesOnScreen");
scriptInterface.RegisterFunction<std::vector<entity_id_t>, std::string, bool, bool, bool, &PickSimilarPlayerEntities>("PickSimilarPlayerEntities");
scriptInterface.RegisterFunction<CFixedVector3D, int, int, &GetTerrainAtScreenPoint>("GetTerrainAtScreenPoint");

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -922,9 +922,17 @@ public:
virtual std::vector<entity_id_t> GetEntitiesByPlayer(player_id_t player)
{
std::vector<entity_id_t> entities;
return GetEntitiesByMask(CalcOwnerMask(player));
}
u32 ownerMask = CalcOwnerMask(player);
virtual std::vector<entity_id_t> GetNonGaiaEntities()
{
return GetEntitiesByMask(((1 << MAX_LOS_PLAYER_ID) - 1) << 1);
}
virtual std::vector<entity_id_t> GetEntitiesByMask(u32 ownerMask)
{
std::vector<entity_id_t> entities;
for (EntityMap<EntityData>::const_iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it)
{

View File

@ -46,6 +46,7 @@ DEFINE_INTERFACE_METHOD_1("ResetActiveQuery", std::vector<entity_id_t>, ICmpRang
DEFINE_INTERFACE_METHOD_3("SetEntityFlag", void, ICmpRangeManager, SetEntityFlag, entity_id_t, std::string, bool)
DEFINE_INTERFACE_METHOD_1("GetEntityFlagMask", u8, ICmpRangeManager, GetEntityFlagMask, std::string)
DEFINE_INTERFACE_METHOD_1("GetEntitiesByPlayer", std::vector<entity_id_t>, ICmpRangeManager, GetEntitiesByPlayer, player_id_t)
DEFINE_INTERFACE_METHOD_0("GetNonGaiaEntities", std::vector<entity_id_t>, ICmpRangeManager, GetNonGaiaEntities)
DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool)
DEFINE_INTERFACE_METHOD_1("ExploreAllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t)
DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories)

View File

@ -192,6 +192,11 @@ public:
*/
virtual std::vector<entity_id_t> GetEntitiesByPlayer(player_id_t player) = 0;
/**
* Returns a list of all entities of all players except gaia.
*/
virtual std::vector<entity_id_t> GetNonGaiaEntities() = 0;
/**
* Toggle the rendering of debug info.
*/