SerialEventCityCreated

Thalassicus

Bytes and Nibblers
Joined
Nov 9, 2005
Messages
11,057
Location
Texas
Has anyone tried using this event? It seems the X and Y values are not the same as what other functions use. :think:

The Y value is always accurate, but the X value varies between -3 and -5 from the actual x value... haven't been able to figure out the pattern...

PHP:
function NewCity(coordinates)
	Players[Game.GetActivePlayer()]:InitUnit( GameInfo.Units.UNIT_ARCHER.ID, coordinates.x, coordinates.y )
end

LuaEvents.SerialEventCityCreated.Add( NewCity )
 
I am using this event, it seems robust and works for cities of all civs regardless of whether human player discovered them.

The coordinate is a hex coordinate, that's why it's a bit different, so you should do:

local cityX, cityY = ToGridFromHex( coordinates.x, coordinates.y );
 
I gradually realized that too. I didn't know there was a function do to the conversion automatically, and spent half an hour figuring it out by hand. :lol:

local cartesianX = (hex.x + math.floor(hex.y / 2)) % mapWidth
local cartesianY = hex.y

It's good there's something built-in for this. I haven't done many things that use the hex form. :crazyeye:
 
I'm not even sure what hex form is. I guess it's needed for something in the engine. Most functions seem to use grid form, but then some events pass coordinates in hex form. I think 2 people were writing the engine and they had different opinions on how to represent coordinates :lol:
 
The hex form is tilted:

attachment.php


Cartesian


attachment.php


Hex
 

Attachments

  • Cartesian.jpg
    Cartesian.jpg
    105.8 KB · Views: 502
  • Hex.JPG
    Hex.JPG
    111.1 KB · Views: 470
Cartesian/grid/rectangular coordinates are the normal method used for most things in life, and is easier for me to understand too.

I suspect the game engine uses the hex system at a lower level... mostly hidden to us, and converted to rectangular for us to see. The hex coordinates are probably easier to calculate which tiles are adjacent, since everything lines up nicely on the boundaries between tiles.
 
My best guess is that the graphiocs/display/UI functions use the cartesian coordinates, and the rules-parts use hex ones. This fits logically with Thal's description, and with the (mostly) consistent use of each for different events/functions.

I hesitate to use the word 'engine', because some of the docs from the devs seem to use 'engine' to mean graphics, whereas most modders seem to use it to mean game rules, so it may lead to confusion. Oh for unambiguous terminology...
 
Firaxis' terms are often a little crazy! :lol: They use "fog of war" to refer to unexplored territory, while most people think of "fog of war" as the grey parts of the map hidden when out of sight.

They also have 3 different ways to talk about if we can see units. There's isVisible and currentlyInvisible... and units can be both! The actual "can I see it" has no explicit name and is calculated on the fly as a combination of the two. :crazyeye:

Most people probably think of:
  • Engine - engine of a car, runs it and rarely seen
  • UI - the stuff we see and interact with, controlled by the engine
 
Back
Top Bottom