What is the turn order in Greed?


I want to know if the human and orge players execute their turns simultaneously in the Greed multiplayer level. I’ve seen some replays where peons cross paths with each other and I’m very curious to know if a certain peon will be guaranteed a coin pickup despite overlap with an opposing player.

I’m pretty sure the turn orders are simultaneously executed (if no player falls behind due to statements running over 4k) because of the way soldiers and knights seem to die exactly at the same moment.

Also, this question leads to another question, how far back do overrunning statements cause your ai to fall in the turn order? This is my current hypothesis: if the players javascript statements run under 4k they are executed at the end of the .25 second frame. If they go over, it takes a whole other frame for the orders to be executed.
So any statements 4000 > x > 8000 will take .5 seconds or two frames to execute. A statement of length 8100 would thus take 3 frames to execute.

Thanks for any answers.


Sides don’t really take turns; each unit in the World updates for each frame. The Combat System will let all units attack before resolving unit deaths, which is why the knights and ogres can mutually kill each other. The Inventory System doesn’t really do this, because two collectors can’t collect the same collectable. In that case, the “first” one gets it, i.e., the first one that was built. If two collectors were built on the same frame, then the one whose builder (the base) came first would be first. For this level, it looks like the Human Base was added to the level editor first. So in that rare situation where the first peasant and peon both go for something and touch it on the same frame, the peasant should get it.

You’re correct about the extra statement delay, except that the entire chooseAction() method executes initially, and then the next chooseAction() call will wait until delay has been served out if that call took more than 4000 statements.

By the way, you can check out all the code for the game engine within the level editor if you are really curious about the details. Code is all in the Components and Systems tabs.


Thanks, that answered all my questions. I was trying to look at the github for the relevant level scripts to help me out, I didn’t realize the level editor had all the game logic in it. Very cool.