Author Topic: Robot Arena 2 - What goes on behind the GUI  (Read 2425 times)

Online apanx

Robot Arena 2 - What goes on behind the GUI
« on: July 25, 2009, 03:22:13 PM »
Long post with lots of text. It is not guaranteed to be all comprehensive or correct.
 
When the Robot Arena 2 executable is loaded. The first thing it does that is related to Python is to load the Main.py found in the Scripts folder. The Main.py starts by importing all the C++ commands that is avaliable in Python form, the plus library. It also reroutes all console output from Python scripts to the Debug box, which makes this an excellent place to add a file output to.
Code: [Select]
class giScript_stdout:
    def write(self, s):
        giScript.debug_stdout(s)
        output = file("debug.txt", "a")
        output.write(str(s))
   
class giScript_stderr:
    def __init__(self):
        self.count = 0
    def write(self, s):
        self.count += 1
        output = file("debug.txt", "a")
        output.write(str(s))
        giScript.debug_stderr(s)
    def flush(self):
        pass

It then initiates the loading of Arenas followed by AI. The Arena and AI folder is interpreted by Python, which starts by reading __init__.py. The Practice arena is the first to be loaded. After that, the loading of all avaliable AI begins which continues by creating a list containing all bindings, which is what bindings.py does. In order to draw up all the GUI portions, the game queries the gib files found under the UI folder. These contain instructions on how to draw up all the elements on the screen.
In order to populate the Player and the AI teams, the game queries the Teams.txt and fills up the slots accordingly. Unfortunately it does not create the folders (Team1, Team2... and so on) if they are missing, leading to problems with creating new teams in-game since the data cannot be saved in a nonexisting path. All components and textures are also loaded at this stage.
 
When a match is started, the Arena chosen is created by the game. Which gets its basic properties from the SuperArena in __init__.py. The resulting Arena is a combination of the python code for the Arena and the SuperArena takes care of the sections that are not defined in the current Arenas own python code.
 
This is followed by a cleaning up of the AI stack which disables all running AI by emptying the running_ai global variable. The game then reads the name of the AI bot and queries the Binding list created earlier for the AI script to be loaded.
 
Every AI gets the Invert and Unstuck tactics assigned to themselves by the __init__.py, or SuperAI. All AIs are additions to the SuperAI, which provides basic functionality to the AI. The code in the SuperAI can be overridden by adding the same section in your own AI.
 
The Arena and AI are activated and the code under the Activate section is run. During the match the code under the Tick section for both the Arena and the AI is run. Usually the time between each tick is 250ms for an Arena and 125ms for an AI. This continues until Winners are declared, or the game quit by user.

Offline DuckRA2

  • *
  • Posts: 1006
  • Rep: 1
    • View Profile
    • Awards
Robot Arena 2 - What goes on behind the GUI
« Reply #1 on: July 25, 2009, 04:51:27 PM »
I got kinda lost, but seems interesting

Offline Reier

  • Rieir
  • *
  • Posts: 8564
  • Rep: 8
  • I GOT 3RD IN RAW1
    • https://www.youtube.com/c
  • Awards old BOTM Winner
    • View Profile
    • Awards
Robot Arena 2 - What goes on behind the GUI
« Reply #2 on: July 25, 2009, 04:58:37 PM »
*Brain short circuts*
ALERT- Another WS coming up...
voted best bot builder two times and counting babayy. the best ra2 builder who has never won an actual tournament match
ReiAI pack for Ironforge
My drawings, and my webcomics
Why online PVP will save RA2
The problem with competitive IRL in RA2
I'm fine with hugging reier

Offline System32

  • *
  • Posts: 4663
  • Rep: 4
  • Reality
    • View Profile
    • Awards
Robot Arena 2 - What goes on behind the GUI
« Reply #3 on: July 25, 2009, 04:58:50 PM »
I think He's saying the scource is already open.
Put this onto your signature if you were part of this crappy fad in '03.

Offline Serge

  • *
  • Posts: 1530
  • Rep: 13
    • View Profile
    • http://www.q3k.org/
    • Awards
Robot Arena 2 - What goes on behind the GUI
« Reply #4 on: July 25, 2009, 05:50:18 PM »
Seems quite logical.

@people wanting raw capture of keys

The RA2 WinAPI window already captures them, and translates the messages concerning them however it wants, probably not minding Python. There is no way we can intercept that, unless we make it capture form a different window. Or use some sort of keylogger mechanism. Maybe a kernel driver connecting to a python module via IPC? It may be a bit overkill, but it will surely work. It will also probably be laggy.
One could also intercept DirectInput, but I never studied DirectX API's, so I know nothing about it.
home | twitter | yt | gmf de/compiler | component freedom | xmpp: q3k@q3k.org | email: q3k@q3k.org

Online apanx

Robot Arena 2 - What goes on behind the GUI
« Reply #5 on: July 25, 2009, 06:33:12 PM »
Well, I tried pyHook, which hooks the keyboard input, but that only works in the GUI parts and not in the game part. It seems like the game uses DirectInput for the actual game part with all 3D stuff. Which cannot be hooked using pyHook. Only by hooking DirectInput, or doing some other esoteric stuff will it be possible to get raw input in-game

Offline Madiaba

Robot Arena 2 - What goes on behind the GUI
« Reply #6 on: July 25, 2009, 10:30:41 PM »
Well, thanks guys. I put in too many hours reading up on py commands and recipes to no avail, and then just gave up a few months ago.
I'm not an expert by any means with DirectX, so the ball's in your court to assess if it will work, or even if it's worth the effort...(though I have a couple cool tweeks raw input could facilitate).
.
Input is appreciated. :)
-Arrogance is a quantity devoid of quality...
-As a client once told me "This is my story, and it's sticking to me!"
-Relationships these days are like the 'Arrival' section of the airport: a lot of baggage is being revealed in one place, and not a lot of it is being correlated to its real owners...

Offline philetbabe

  • *
  • Posts: 497
  • Rep: 2
  • Drop D
    • View Profile
    • Awards
Robot Arena 2 - What goes on behind the GUI
« Reply #7 on: July 26, 2009, 06:45:23 AM »
Quote from: apanx;54830
Well, I tried pyHook, which hooks the keyboard input, but that only works in the GUI parts and not in the game part. It seems like the game uses DirectInput for the actual game part with all 3D stuff. Which cannot be hooked using pyHook. Only by hooking DirectInput, or doing some other esoteric stuff will it be possible to get raw input in-game


how do you do to use pyHook ?
Does just installing the library and then 'import pyhook' inside one of the file.py (arena or ai) is enough to let you use the pyHook function ?

first post : clear and concise -as long as one get a little understanding about pyhon. Thank's.