Jump to content

Ticket #1848: Rally points on minimap with building selected


Recommended Posts

Hi, I'm new to this game.

I would like to start participate into 0 A.D. development.

I'm going to start with ticket 1848.

Wondering if anyone can help on understanding the structure of 0 A.D. development files.

I found the fireworldclickevent.

I think i might need to find the place where it identifys the selection of a building.

anyone could tell me where it is? or give me some suggestions or ideas?

thanks in advance

  • Like 1
Link to comment
Share on other sites

So to carry on this discussion CMiniMap::FireWorldClickEvent() seems to be sending a ScriptEvent("worldclick", coords);

Where would this event be received in the JS ?

------

ok its received in gui/session/session.xml and sent to handleMinimapEvent

Edited by madmax
Link to comment
Share on other sites

You should take a look at gui/session/input.js around line 415 (determineAction()).

The worldclick is handled in gui/session/session.xml which just calls handleMinimapEvents() in input.js (which is probably where you should start with this ticket).

Link to comment
Share on other sites

Hmm was looking at

function determineAction(x, y, fromMinimap)

It seems the mouse x, y that gets passed in is undefined.

If I right click on the world somewhere then the x, y is passed in correctly so the rally point is set. But if I right click on the minimap then the x,y is undefined. Seems like the code that sets the rally point is not the issue. But the interpretation of the mouse position when right clicked on the minimap is the problem.

Edited by madmax
Link to comment
Share on other sites

Hmm so in input.js the code is as follows :


function handleMinimapEvent(target)
{
// Partly duplicated from handleInputAfterGui(), but with the input being
// world coordinates instead of screen coordinates.
if (inputState == INPUT_NORMAL)
{
var fromMinimap = true;
var action = determineAction(undefined, undefined, fromMinimap);
if (!action)
return false;
....
..........

I tried making it :


function handleMinimapEvent(target)
{
// Partly duplicated from handleInputAfterGui(), but with the input being
// world coordinates instead of screen coordinates.
if (inputState == INPUT_NORMAL)
{
var fromMinimap = true;
var action = determineAction(target.x, target.z, fromMinimap);
if (!action)
return false;

Doesnt seem to work though. I think the call to targets = Engine.PickEntitiesAtPoint(x, y) in determineAction() is the key here. Unless Engine.PickEntitiesAtPoint() gets called and returns valid targets the rally point cant be set.

Edited by madmax
Link to comment
Share on other sites

Does anyone know about the various co-ordinates system in use. As far as I can see there are 2 :

world-coords : Used to locate entities on the 0ad map, has x,y & z

screen-coords: Only x & y, used to locate mouse pointer, minimap click point etc.

So everything is actually fine till :


function handleMinimapEvent(target)
{
..
...

case "set-rallypoint":
Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": target.x, "z": target.z});
// Display rally point at the new coordinates, to avoid display lag
Engine.GuiInterfaceCall("DisplayRallyPoint", {
"entities": selection,
"x": target.x,
"z": target.z
});
return true;
...

Also if I understand correctly, void CMiniMap::GetMouseWorldCoordinates(float& x, float& z) will convert the mouse screen-coordinates to the 0ad world coods so the rally point on the terrain can be located ?


void CMiniMap::GetMouseWorldCoordinates(float& x, float& z)
{
// Determine X and Z according to proportion of mouse position and minimap
CPos mousePos = GetMousePos();
float px = (mousePos.x - m_CachedActualSize.left) / m_CachedActualSize.GetWidth();
float py = (m_CachedActualSize.bottom - mousePos.y) / m_CachedActualSize.GetHeight();
float angle = GetAngle();
// Scale world coordinates for shrunken square map
x = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5);
z = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(py-0.5) + sin(angle)*(px-0.5)) + 0.5);
}

Edited by madmax
Link to comment
Share on other sites

  • 4 weeks later...

There are at least 3 coordinate systems:

-World position

-"Tile" position (usually world position /4 except Y which if I recall correctly doesn't change), which theoretically shouldn't really be used by simulation code.

-screen position.

Your assumption seems to be right to me (you can see it's multiplied by Terrain_Tile_Size, which is 4, to go from world to "tile" position)

Giving a look at the code, it seems to work properly, and detect the action properly (if I "warn(uneval(action))" right after calling determineaction, I get "set-rallypoint". However apparently the DetermineAction thing expects "GetActionInfo" to return position and tooltip information, which it obviously does not.

I suggest you fix the bug in GetActionInfo: it should return more information for set-rallypoint. This should make it work, unless something else goes wrong.

Link to comment
Share on other sites

  • 3 weeks later...

hi, guys. sorry. i got some family issues. i started the topic. then i banished XD. sorry about that.

and i'm back, i would be pretty much full time working on this topic and the game since i'm going to graduate XD.

wondering if anyone made any progress so i could just pick it up and continue to save some time?

Edited by TrinityDeath
Link to comment
Share on other sites

Does anyone know about the various co-ordinates system in use. As far as I can see there are 2 :

world-coords : Used to locate entities on the 0ad map, has x,y & z

screen-coords: Only x & y, used to locate mouse pointer, minimap click point etc.

So everything is actually fine till :


function handleMinimapEvent(target)
{
..
...

case "set-rallypoint":
Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": target.x, "z": target.z});
// Display rally point at the new coordinates, to avoid display lag
Engine.GuiInterfaceCall("DisplayRallyPoint", {
"entities": selection,
"x": target.x,
"z": target.z
});
return true;
...

Also if I understand correctly, void CMiniMap::GetMouseWorldCoordinates(float& x, float& z) will convert the mouse screen-coordinates to the 0ad world coods so the rally point on the terrain can be located ?


void CMiniMap::GetMouseWorldCoordinates(float& x, float& z)
{
// Determine X and Z according to proportion of mouse position and minimap
CPos mousePos = GetMousePos();
float px = (mousePos.x - m_CachedActualSize.left) / m_CachedActualSize.GetWidth();
float py = (m_CachedActualSize.bottom - mousePos.y) / m_CachedActualSize.GetHeight();
float angle = GetAngle();
// Scale world coordinates for shrunken square map
x = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5);
z = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(py-0.5) + sin(angle)*(px-0.5)) + 0.5);
}

There are at least 3 coordinate systems:

-World position

-"Tile" position (usually world position /4 except Y which if I recall correctly doesn't change), which theoretically shouldn't really be used by simulation code.

-screen position.

Your assumption seems to be right to me (you can see it's multiplied by Terrain_Tile_Size, which is 4, to go from world to "tile" position)

Giving a look at the code, it seems to work properly, and detect the action properly (if I "warn(uneval(action))" right after calling determineaction, I get "set-rallypoint". However apparently the DetermineAction thing expects "GetActionInfo" to return position and tooltip information, which it obviously does not.

I suggest you fix the bug in GetActionInfo: it should return more information for set-rallypoint. This should make it work, unless something else goes wrong.

any one knows where i should look at for normal click with a building selected? ( not from mini map)

i'm thinking this should make the rally point set. and it works fine.

but from mini map. it's not working.

i want to have a look at both of them. and compare them. i think it should be a tiny mistake. and i don't think the coordinates are wrong. because the case "move" works fine with coordinates target.x and target.z.

currently i can't find the normal click not through mini map. hope someone can help me with it

please correct me if i'm wrong.

thanks in advance.

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...