Jump to content

Attack notification


Recommended Posts

Ok this is how I am planning to modifiy the unit rendering code in the minimap :


PROFILE_START("minimap units");
// Don't enable GL_POINT_SMOOTH because it's far too slow
// (~70msec/frame on a GF4 rendering a thousand points)
glPointSize(3.f);
float sx = (float)m_Width / ((m_MapSize - 1) * TERRAIN_TILE_SIZE);
float sy = (float)m_Height / ((m_MapSize - 1) * TERRAIN_TILE_SIZE);
CSimulation2::InterfaceList ents = sim->GetEntitiesWithInterface(IID_Minimap);
std::vector<MinimapUnitVertex> vertexArray;
vertexArray.reserve(ents.size());

for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
{
MinimapUnitVertex v;
ICmpMinimap* cmpMinimap = static_cast<ICmpMinimap*>(it->second);
entity_pos_t posX, posZ;
if (cmpMinimap->GetRenderData(v.r, v.g, v.b, posX, posZ))
{
ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetPlayerID());
if (vis != ICmpRangeManager::VIS_HIDDEN)
{
v.x = posX.ToFloat()*sx;
v.y = -posZ.ToFloat()*sy;

// try to find the entity id in it->first in the hashmap of unit ids to ping and set pingUnit to true if found

if ( pingUnit && m_Dim > 50) {
v.a = 255;
v.r = 255;
v.g = 100;
v.b = 100;
}

vertexArray.push_back(v);

}
}
}

m_Dim = (m_Dim + 1) > 100 ? 0 : (m_Dim + 1);

if (!vertexArray.empty())
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
shader->VertexPointer(2, GL_FLOAT, sizeof(MinimapUnitVertex), &vertexArray[0].x);
shader->ColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MinimapUnitVertex), &vertexArray[0].r);
}
else
{
glVertexPointer(2, GL_FLOAT, sizeof(MinimapUnitVertex), &vertexArray[0].x);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MinimapUnitVertex), &vertexArray[0].r);
}
glDrawArrays(GL_POINTS, 0, (GLsizei)vertexArray.size());
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
PROFILE_END("minimap units");

I ll m_Dim a member of class Minimap. Figuring out right now how to get the attacked entities across from zoot's JS code.

Edited by madmax
Link to comment
Share on other sites

How can I get the current turn number of the sim in C++ ?

g_Game->GetTurnManager() or something similar I guess.

I need the turn number to switch off attacked units being pinged after say 100 turns. That way units that are under attack are not pinged forever.

---------------------

ok so I did this change today in messages.js :



function handleNotifications()
{
...
.......
if (notification.player == Engine.GetPlayerID())
{
Engine.GuiInterfaceCall("PlaySound", { "name":"attacked", "entity": notification.message.target });
Engine.PingMinimap({ "entity": notification.message.target });
}
..
...
}

Also in C++, in ScriptedFunctions.cpp I added to GuiScriptingInit() the following line


...
// Minimap functions
scriptInterface.RegisterFunction<void, entity_id_t, &PingMinimap>("PingMinimap");
....

Then above GuiScriptingInit() added :


/**
* Ping the minimap at the location of the passed entity to indicate something
* (currently an attack)
* @param entityid unit id to ping
*/
void PingMinimap(void* UNUSED(cbdata), entity_id_t entityid)
{
g_Console->InsertMessage(L"Ping received from %d", entityid);
LOGWARNING(L"Ping got from E:%d", entityid);
}

But I get a Javascript warning in the log :


WARNING: JavaScript warning: gui/session/messages.js line 86 Script value conversion check failed: JSVAL_IS_NUMBER(v) (got type object)
WARNING: Ping got from E:0

Wonder why this error is coming. I dont think the entity id would be 0 if this warning can be fixed.

Also how do I access the minimap from

void PingMinimap(void* UNUSED(cbdata), entity_id_t entityid).

This is to add the pinged entity to some kind of list/map so while rendering I can blink it.

Edited by madmax
Link to comment
Share on other sites

That error is because you are passing an object from JS:

Engine.PingMinimap({ "entity": notification.message.target });

The stuff in curly braces is an object literal. You should probably just pass the entity ID directly:

Engine.PingMinimap(notification.message.target);

Edited by zoot
Link to comment
Share on other sites

ok, Ping got from E:35

Seems good. Now to access the minimap from the function in ScriptedFunctions.

Hmm most functions there seem to use something like :

g_Game->GetWorld()->GetTerrain()->GetHeightMipmap().DumpToDisk(filename);

or

guiManager->GetScriptInterface().GetContext()

or static cast some passed cbdata :

CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);

I ll check the functions in for guiManager since ps/Game.h doesnt have any minimap, so apparently the minimap object is not part of the game. Probably only the gui.

Edited by madmax
Link to comment
Share on other sites

Yes, and calling CGUI::FindObjectByName("minimap") should return a IGUIObject* which I can static cast to CMiniMap* and access a function there.

I guess static casts should be fine, dynamic_casts are supposed to be bad in OOP

Or rather I should call CGUIManager::FindObjectByName() which wraps the current CGUI object.

Edited by madmax
Link to comment
Share on other sites

ok, yeah so the circle and square are sprites stretched across the screen for drawing the minimap.

<action on="WorldClick">handleMinimapEvent(arguments[0]);</action>

Responds to clicks anywhere on the screen and I guess it will check if the click was inside it. Whats the library being used which can construct the GUI from XML ! ?

Edited by madmax
Link to comment
Share on other sites

ah ok :)

So I am planning to make it such that entities will be pinged for a certain number of turns and then removed from the list of entities to be pinged. Unless its added again which means it was attacked again. This would keep the minimap clean.

Maybe I should also stop blinking the attacked entity a few turns before its removed and the entity is rendered with normal colors again.

------------

ok got a basic implementation going :

The size of the blinking dot is the same size as the unit being attacked. Maybe I should make it a bit bigger ? Also the pinging occurs only as long as the entity is alive. Also since its just one unit which is reported, the size of the dot is quite small. If neighbouring units were also reported as being attacked then we would get a better blinking blob !

I need to place a global constant called MAX_PING_TURNS after which the entity will no longer be pinged. Is there some header where all global constants are placed or can I just plop it into Minimap.h ? Maybe it can be made a configurable parameter later on for players who want the attack notifications to be around longer ? Or maybe it does not need to be changeable ?

Edited by madmax
Link to comment
Share on other sites

Also the pinging occurs only as long as the entity is alive.

There is a small problem with this; if we have a clump of units, and the one that was 'pinged' dies, the blinking will presumably stop even though the skirmish continues for the other units. I'm not quite sure how to address that?

Edited by zoot
Link to comment
Share on other sites

Yes, I will do that, just adding the ping timeout thing where the pinging stops after some time.

Do I make a new branch and then modify the files ? Or I ll put in the changes in attack-notification branch and commit. Can you tell me a few quick commands to commit :P ....lazy !!

Link to comment
Share on other sites

You can just use the existing 'attack-notification' branch, since the branch in your repo is seperate from the one in mine.

You need to "git add" all the files you have modified and/or created. Then "git commit" or:

git commit -m "Some helpful commit message here."

Once you've committed to your local repo, you should be able to push as described in the link above.

Edited by zoot
Link to comment
Share on other sites

The size of the blinking dot is the same size as the unit being attacked. Maybe I should make it a bit bigger ?

Wow, that's very cool. I would probably make it a bit bigger and blink faster. But you're definitely on the right track. :)

Also the pinging occurs only as long as the entity is alive.

That seems like a fairly bit issue, but I have no idea how to solve it. :(

Also since its just one unit which is reported, the size of the dot is quite small. If neighbouring units were also reported as being attacked then we would get a better blinking blob !

Yes, it probably should scale to the size of the attack, but oddly enough I don't think that's all that critical, although it would be very nice to have.

Link to comment
Share on other sites

Ok this is what I did, but I still dont see my commit in github :(

I have committed just 2 files, 2 more to do but the commit should appear.


abhi@ABHI-PC /f/Code/0ad/0ad (attack-notification)
$ git commit -m "Just Testing"
# On branch attack-notification
nothing to commit, working directory clean
abhi@ABHI-PC /f/Code/0ad/0ad (attack-notification)
$ git commit -m "Just Testing"
# On branch attack-notification
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: source/gui/MiniMap.h
#
no changes added to commit (use "git add" and/or "git commit -a")
abhi@ABHI-PC /f/Code/0ad/0ad (attack-notification)
$ git add source/gui/MiniMap.h
abhi@ABHI-PC /f/Code/0ad/0ad (attack-notification)
$ git commit -m "Just Testing"
[attack-notification f482178] Just Testing
1 file changed, 33 insertions(+), 1 deletion(-)
abhi@ABHI-PC /f/Code/0ad/0ad (attack-notification)
$ git commit -m "Just Testing"
# On branch attack-notification
# Your branch is ahead of 'origin/attack-notification' by 1 commit.
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: source/gui/MiniMap.cpp
#
no changes added to commit (use "git add" and/or "git commit -a")
abhi@ABHI-PC /f/Code/0ad/0ad (attack-notification)
$ git add source/gui/MiniMap.cpp
abhi@ABHI-PC /f/Code/0ad/0ad (attack-notification)
$ git commit -m "Commit the ping minimap function added to the CMiniMap code"
[attack-notification 768cf71] Commit the ping minimap function added to the CMin
iMap code
1 file changed, 75 insertions(+), 3 deletions(-)
abhi@ABHI-PC /f/Code/0ad/0ad (attack-notification)
$

Edited by madmax
Link to comment
Share on other sites

Great. I get errors when building, though:

$ make -j9
==== Building mocks_real (release) ====
==== Building network (release) ====
==== Building simulation2 (release) ====
==== Building scriptinterface (release) ====
==== Building engine (release) ====
==== Building graphics (release) ====
==== Building gui (release) ====
==== Building mongoose (release) ====
==== Building atlas (release) ====
==== Building lowlevel (release) ====
==== Building mocks_test (release) ====
==== Building AtlasObject (release) ====
==== Building AtlasScript (release) ====
==== Building Collada (release) ====
==== Building AtlasUI (release) ====
MiniMap.cpp
CGUI.cpp
ScriptFunctions.cpp
==== Building ActorEditor (release) ====
In file included from /usr/include/c++/4.7/unordered_map:35:0,
from ../../../source/gui/MiniMap.h:22,
from ../../../source/gui/MiniMap.cpp:22:
/usr/include/c++/4.7/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
In file included from /usr/include/c++/4.7/unordered_map:35:0,
from ../../../source/gui/MiniMap.h:22,
from ../../../source/gui/CGUI.cpp:41:
/usr/include/c++/4.7/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
../../../source/gui/scripting/ScriptFunctions.cpp:26:25: fatal error: gui/Minimap.h: No such file or directory
compilation terminated.
In file included from ../../../source/gui/CGUI.cpp:41:0:
../../../source/gui/MiniMap.h:34:9: error: ‘unordered_map’ in namespace ‘std’ does not name a type
../../../source/gui/MiniMap.h:111:2: error: ‘map_Ping’ does not name a type
In file included from ../../../source/gui/MiniMap.cpp:22:0:
../../../source/gui/MiniMap.h:34:9: error: ‘unordered_map’ in namespace ‘std’ does not name a type
../../../source/gui/MiniMap.h:111:2: error: ‘map_Ping’ does not name a type
../../../source/gui/MiniMap.cpp: In member function ‘void CMiniMap::AddPing(entity_id_t)’:
../../../source/gui/MiniMap.cpp:257:2: error: ‘m_EntitiesToPing’ was not declared in this scope
../../../source/gui/MiniMap.cpp: In member function ‘virtual void CMiniMap::Draw()’:
../../../source/gui/MiniMap.cpp:488:5: error: ‘map_Ping’ has not been declared
../../../source/gui/MiniMap.cpp:488:24: error: expected ‘;’ before ‘pingIter’
../../../source/gui/MiniMap.cpp:490:10: error: ‘pingIter’ was not declared in this scope
../../../source/gui/MiniMap.cpp:490:22: error: ‘m_EntitiesToPing’ was not declared in this scope
../../../source/gui/MiniMap.cpp:524:5: error: ‘map_Ping’ has not been declared
../../../source/gui/MiniMap.cpp:524:24: error: expected ‘;’ before ‘pingIter’
../../../source/gui/MiniMap.cpp:526:10: error: ‘pingIter’ was not declared in this scope
../../../source/gui/MiniMap.cpp:526:22: error: ‘m_EntitiesToPing’ was not declared in this scope
../../../source/gui/MiniMap.cpp:544:32: error: ‘m_EntitiesToPing’ was not declared in this scope
../../../source/gui/MiniMap.cpp: In member function ‘virtual void CMiniMap::Destroy()’:
../../../source/gui/MiniMap.cpp:704:2: error: ‘m_EntitiesToPing’ was not declared in this scope
make[1]: *** [obj/gui_Release/ScriptFunctions.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [obj/gui_Release/MiniMap.o] Error 1
make[1]: *** [obj/gui_Release/CGUI.o] Error 1
make: *** [gui] Error 2

Link to comment
Share on other sites

ok, this is in linux. Strange I thought that std::unordered_map would work without any issues.

I compiled on Windows.

Looking into it. If it says unordered_map is in C++ 2011, then I ll change it to std::map even though std::unordered_map is faster.

Edited by madmax
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...