forked from soundmud/soundrts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_desync.py
132 lines (95 loc) · 3.03 KB
/
test_desync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#! python2.7
from multiprocessing import Process
import os
import time
import win32gui
from soundrts import config
config.mods = "crazymod9beta10"
from soundrts import worldplayercomputer2 as wpc2
from soundrts.lib.nofloat import PRECISION
class Computer2ForTests(wpc2.Computer2):
def cheat(self):
self.has = lambda x: True
self.resources = [1000 * PRECISION for _ in self.resources]
_play = wpc2.Computer2.play
def play(self):
self.cheat()
self._play()
wpc2.Computer2 = Computer2ForTests
from soundrts.lib.voice import voice
from soundrts import clientmain
from soundrts.game import MultiplayerGame
from soundrts import servermain
from soundrts import world
def do_nothing(*a, **k):
pass
def remove_voice():
voice._say_now = do_nothing
voice.item = do_nothing
voice.info = do_nothing
MultiplayerGame._countdown = do_nothing
def set_position(x, y):
os.environ['SDL_VIDEO_WINDOW_POS'] = "%s,%s" % (x, y)
def run_client(n, auto):
if 0:#n == 0:
world.PROFILE = True
if 1:#n != 0:
remove_voice()
set_position(0, n * 110 + 50)
clientmain.init_media()
clientmain.connect_and_play(auto=auto)
def run_server():
hwnd = win32gui.GetForegroundWindow()
win32gui.MoveWindow(hwnd, 400, 0, 800, 800, True)
servermain.start_server(parameters="no_metaserver")
class Create:
def __init__(self, map_index, speed, public=""):
self.map_index = map_index
self.speed = speed
self.public = public
def run(self, menu):
menu.push("create %s %s %s" % (self.map_index, self.speed, self.public))
return True
class Invite:
def __init__(self, nb):
self.nb = nb
def run(self, menu):
if getattr(menu, "available_players", False):
menu.push("invite %s" % menu.available_players[0])
self.nb -= 1
if self.nb == 0:
return True
class InviteAI:
def __init__(self, easy=0, aggressive=0, ai2=0):
self.easy = easy
self.aggressive = aggressive
self.ai2 = ai2
def run(self, menu):
for _ in range(self.easy):
menu.push("invite_easy")
time.sleep(.1)
for _ in range(self.aggressive):
menu.push("invite_aggressive")
time.sleep(.1)
for _ in range(self.ai2):
menu.push("invite_ai2")
time.sleep(.1)
return True
class Register:
def run(self, menu):
if menu.invitations:
menu.push("register %s" % menu.invitations[0][0])
return True
class Start:
def run(self, menu):
if len(menu.registered_players) >= menu.map.nb_players_min:
menu.push("start")
return True
if __name__ == "__main__":
n = 1
Process(target=run_server).start()
ais = (0, 1, 10)
#ais = (1, 1, 10)
Process(target=run_client, args=(0, [Create(10, 20), Invite(n), InviteAI(*ais), Start()], )).start()
for i in range(n):
Process(target=run_client, args=(i + 1, [Register()], )).start()