Skip to content

Commit 38d5938

Browse files
committed
initial generation of python interop
1 parent 036f723 commit 38d5938

File tree

11 files changed

+967
-0
lines changed

11 files changed

+967
-0
lines changed

python/bot/bot.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from uwapi.game import game
2+
3+
class Bot:
4+
isConfigured = False
5+
workStep = 0 # save some cpu cycles by splitting work over multiple steps
6+
7+
def AttackNearestEnemies(self):
8+
pass # todo
9+
10+
def AssignRandomRecipes(self):
11+
pass # todo
12+
13+
def Configure(self):
14+
if isConfigured:
15+
return
16+
isConfigured = True
17+
18+
game.SetPlayerName("bot-cs")
19+
game.PlayerJoinForce(0) # create new force
20+
game.SetForceColor(1, 0, 0)
21+
# todo choose race
22+
23+
def Updating(self, stepping: bool):
24+
if game.GameState() == UwGameStateEnum.Session:
25+
self.Configure()
26+
return
27+
28+
if not stepping:
29+
return
30+
31+
workStep += 1
32+
match workStep % 10: # save some cpu cycles by splitting work over multiple steps
33+
case 1:
34+
self.AttackNearestEnemies()
35+
case 5:
36+
self.AssignRandomRecipes()
37+
38+
def __init__(self):
39+
game.LogInfo("bot-py start")
40+
if not game.TryReconnect():
41+
game.SetConnectStartGui(True)
42+
if not game.ConnectEnvironment():
43+
game.ConnectNewServer()
44+
game.LogInfo("bot-py done")

python/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from uwapi.library import UwapiLibrary
2+
from bot.bot import Bot
3+
4+
if __name__ == "__main__":
5+
with UwapiLibrary():
6+
Bot()

python/uwapi/admin.py

Whitespace-only changes.

python/uwapi/commands.py

Whitespace-only changes.

python/uwapi/entity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
class Entity:
3+
def __init__(self):
4+
pass

python/uwapi/game.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from .interop import *
2+
3+
class Game:
4+
_instance = None
5+
6+
def __new__(cls):
7+
if cls._instance is None:
8+
cls._instance = super().__new__(cls)
9+
return cls._instance
10+
11+
def LogInfo(self, message: str) -> None:
12+
interop.uwLog(UwSeverityEnum.Info, message)
13+
14+
def TryReconnect(self) -> bool:
15+
return interop.uwTryReconnect()
16+
17+
def SetConnectStartGui(self, enabled: bool, extraCmdParams: str = "") -> None:
18+
return interop.uwSetConnectStartGui(enabled, extraCmdParams)
19+
20+
def ConnectEnvironment(self) -> bool:
21+
return interop.uwConnectEnvironment()
22+
23+
def ConnectNewServer(self, visibility: int = 0, name: str = "", extraCmdParams: str = "") -> None:
24+
interop.uwConnectNewServer(visibility, name, extraCmdParams)
25+
26+
game = Game()

0 commit comments

Comments
 (0)