pyscreeps-arena 0.3.5__py3-none-any.whl → 0.4a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyscreeps_arena/__init__.py +2 -1
- pyscreeps_arena/compiler.py +71 -20
- pyscreeps_arena/core/const.py +1 -1
- pyscreeps_arena/project.7z +0 -0
- {pyscreeps_arena-0.3.5.dist-info → pyscreeps_arena-0.4a0.dist-info}/METADATA +1 -1
- {pyscreeps_arena-0.3.5.dist-info → pyscreeps_arena-0.4a0.dist-info}/RECORD +9 -9
- {pyscreeps_arena-0.3.5.dist-info → pyscreeps_arena-0.4a0.dist-info}/entry_points.txt +1 -0
- {pyscreeps_arena-0.3.5.dist-info → pyscreeps_arena-0.4a0.dist-info}/WHEEL +0 -0
- {pyscreeps_arena-0.3.5.dist-info → pyscreeps_arena-0.4a0.dist-info}/top_level.txt +0 -0
pyscreeps_arena/__init__.py
CHANGED
|
@@ -7,6 +7,7 @@ def CMD_NewProject():
|
|
|
7
7
|
"""
|
|
8
8
|
cmd:
|
|
9
9
|
pyscreeps-arena [project_path]
|
|
10
|
+
arena [project_path]
|
|
10
11
|
|
|
11
12
|
* 复制"src" "game" "build.py" 到指定目录
|
|
12
13
|
|
|
@@ -14,7 +15,7 @@ def CMD_NewProject():
|
|
|
14
15
|
|
|
15
16
|
"""
|
|
16
17
|
if len(sys.argv) < 2:
|
|
17
|
-
print("Usage: pyarena new [project_path]")
|
|
18
|
+
print("Usage: pyarena new [project_path]\n# or\narena new [project_path]")
|
|
18
19
|
return
|
|
19
20
|
project_path = sys.argv[1]
|
|
20
21
|
if not os.path.exists(project_path):
|
pyscreeps_arena/compiler.py
CHANGED
|
@@ -43,12 +43,12 @@ class Compiler_Const:
|
|
|
43
43
|
|
|
44
44
|
TOTAL_INSERT_AT_HEAD = """
|
|
45
45
|
import { createConstructionSite, findClosestByPath, findClosestByRange, findInRange, findPath, getCpuTime, getDirection, getHeapStatistics, getObjectById, getObjects, getObjectsByPrototype, getRange, getTerrainAt, getTicks,} from 'game/utils';
|
|
46
|
-
import { ConstructionSite, Creep, GameObject, OwnedStructure, Resource, Source, Structure, StructureContainer, StructureExtension, StructureRampart, StructureRoad, StructureSpawn, StructureWall, StructureTower} from 'game/prototypes';
|
|
46
|
+
import { ConstructionSite as GameConstructionSite, Creep as GameCreep, GameObject as GameObjectProto, OwnedStructure, Resource as GameResource, Source as GameSource, Structure as GameStructure, StructureContainer as GameStructureContainer, StructureExtension as GameStructureExtension, StructureRampart as GameStructureRampart, StructureRoad as GameStructureRoad, StructureSpawn as GameStructureSpawn, StructureWall as GameStructureWall, StructureTower as GameStructureTower} from 'game/prototypes';
|
|
47
47
|
import { ATTACK, ATTACK_POWER, BODYPART_COST, BODYPART_HITS, BOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT, BUILD_POWER, CARRY, CARRY_CAPACITY, CONSTRUCTION_COST, CONSTRUCTION_COST_ROAD_SWAMP_RATIO, CONSTRUCTION_COST_ROAD_WALL_RATIO, CONTAINER_CAPACITY, CONTAINER_HITS, CREEP_SPAWN_TIME, DISMANTLE_COST, DISMANTLE_POWER, ERR_BUSY, ERR_FULL, ERR_INVALID_ARGS, ERR_INVALID_TARGET, ERR_NAME_EXISTS, ERR_NOT_ENOUGH_ENERGY, ERR_NOT_ENOUGH_EXTENSIONS, ERR_NOT_ENOUGH_RESOURCES, ERR_NOT_FOUND, ERR_NOT_IN_RANGE, ERR_NOT_OWNER, ERR_NO_BODYPART, ERR_NO_PATH, ERR_TIRED, EXTENSION_ENERGY_CAPACITY, EXTENSION_HITS, HARVEST_POWER, HEAL, HEAL_POWER, LEFT, MAX_CONSTRUCTION_SITES, MAX_CREEP_SIZE, MOVE, OBSTACLE_OBJECT_TYPES, OK, RAMPART_HITS, RAMPART_HITS_MAX, RANGED_ATTACK, RANGED_ATTACK_DISTANCE_RATE, RANGED_ATTACK_POWER, RANGED_HEAL_POWER, REPAIR_COST, REPAIR_POWER, RESOURCES_ALL, RESOURCE_DECAY, RESOURCE_ENERGY, RIGHT, ROAD_HITS, ROAD_WEAROUT, SOURCE_ENERGY_REGEN, SPAWN_ENERGY_CAPACITY, SPAWN_HITS, STRUCTURE_PROTOTYPES, TERRAIN_PLAIN, TERRAIN_SWAMP, TERRAIN_WALL, TOP, TOP_LEFT, TOP_RIGHT, TOUGH, TOWER_CAPACITY, TOWER_COOLDOWN, TOWER_ENERGY_COST, TOWER_FALLOFF, TOWER_FALLOFF_RANGE, TOWER_HITS, TOWER_OPTIMAL_RANGE, TOWER_POWER_ATTACK, TOWER_POWER_HEAL, TOWER_POWER_REPAIR, TOWER_RANGE, WALL_HITS, WALL_HITS_MAX, WORK} from 'game/constants';
|
|
48
48
|
|
|
49
49
|
import {arenaInfo} from "game";
|
|
50
50
|
import {Visual} from "game/visual"
|
|
51
|
-
import {searchPath} from "game/path-finder"
|
|
51
|
+
import {searchPath, CostMatrix} from "game/path-finder"
|
|
52
52
|
"""
|
|
53
53
|
|
|
54
54
|
TOTAL_INSERT_BEFORE_MAIN = """
|
|
@@ -59,19 +59,36 @@ export var sch = Scheduler();
|
|
|
59
59
|
var monitor = Monitor(2);
|
|
60
60
|
know.now = 0;
|
|
61
61
|
|
|
62
|
+
StageMachineLogicMeta.__types__ = []; // 清空js首次构造时引入的数据
|
|
63
|
+
StageMachineLogicMeta.__recursive__ = []; // 清空js首次构造时引入的数据
|
|
62
64
|
__init_my_exists_creep_before_k__();
|
|
65
|
+
let knowCost = 0;
|
|
66
|
+
let monitorCost = 0;
|
|
67
|
+
let stepCost = 0;
|
|
68
|
+
let timeLine = 0;
|
|
63
69
|
export var loop = function () {
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
get.handle();
|
|
71
|
+
know.now = get.now;
|
|
72
|
+
timeLine = get.cpu_us();
|
|
73
|
+
know.handle();
|
|
74
|
+
knowCost = get.cpu_us() - timeLine;
|
|
66
75
|
if (know.now === 1) {
|
|
67
76
|
std.show_welcome();
|
|
68
77
|
init (know);
|
|
69
78
|
}
|
|
70
79
|
|
|
80
|
+
timeLine = get.cpu_us();
|
|
71
81
|
monitor.handle();
|
|
82
|
+
monitorCost = get.cpu_us() - timeLine;
|
|
83
|
+
for (const creep of get.creeps()){
|
|
84
|
+
creep.handle();
|
|
85
|
+
}
|
|
72
86
|
step (know);
|
|
87
|
+
timeLine = get.cpu_us();
|
|
73
88
|
sch.handle();
|
|
89
|
+
stepCost = get.cpu_us() - timeLine;
|
|
74
90
|
std.show_usage ();
|
|
91
|
+
print("knowCost:", knowCost, "monitorCost:", monitorCost, "stepCost:", stepCost);
|
|
75
92
|
};
|
|
76
93
|
"""
|
|
77
94
|
|
|
@@ -109,42 +126,58 @@ export var loop = function () {
|
|
|
109
126
|
|
|
110
127
|
ARENA_IMPORTS_GETTER = {
|
|
111
128
|
const.ARENA_GREEN: lambda: f"""
|
|
112
|
-
class
|
|
129
|
+
class GameBodyPart{{
|
|
113
130
|
constructor(){{
|
|
114
131
|
}}
|
|
115
132
|
}};
|
|
116
|
-
|
|
133
|
+
class GameAreaEffect{{
|
|
134
|
+
constructor(){{
|
|
135
|
+
}}
|
|
136
|
+
}};
|
|
137
|
+
class GameFlag{{
|
|
138
|
+
constructor(){{
|
|
139
|
+
}}
|
|
140
|
+
}};
|
|
141
|
+
const GameScoreCollector = GameStructureSpawn;
|
|
117
142
|
""",
|
|
118
143
|
const.ARENA_BLUE: lambda: f"""
|
|
119
|
-
const
|
|
120
|
-
|
|
144
|
+
const GameScoreCollector = GameStructureSpawn;
|
|
145
|
+
class GameAreaEffect{{
|
|
146
|
+
constructor(){{
|
|
147
|
+
}}
|
|
148
|
+
}};
|
|
149
|
+
import {{ Flag as GameFlag, BodyPart as GameBodyPart}} from 'arena/season_{config.season}/capture_the_flag/basic';
|
|
121
150
|
""",
|
|
122
151
|
const.ARENA_RED: lambda: f"""
|
|
123
|
-
class
|
|
152
|
+
class GameBodyPart{{
|
|
124
153
|
constructor(){{
|
|
125
154
|
}}
|
|
126
155
|
}};
|
|
127
|
-
|
|
156
|
+
class GameFlag{{
|
|
157
|
+
constructor(){{
|
|
158
|
+
}}
|
|
159
|
+
}};
|
|
160
|
+
import {{ RESOURCE_SCORE, ScoreCollector as GameScoreCollector, AreaEffect as GameAreaEffect, EFFECT_DAMAGE, EFFECT_FREEZE }} from 'arena/season_{config.season}/collect_and_control/basic';
|
|
128
161
|
|
|
129
162
|
import ("arena/season_{config.season}/collect_and_control/basic")
|
|
130
163
|
.then((module) => {{ const RESOURCE_SCORE_X = module.RESOURCE_SCORE_X; const RESOURCE_SCORE_Y = module.RESOURCE_SCORE_Y; const RESOURCE_SCORE_Z = module.RESOURCE_SCORE_Z; }})
|
|
131
164
|
.catch((error) => {{ }});
|
|
132
165
|
""",
|
|
133
166
|
const.ARENA_GRAY: lambda: f"""
|
|
134
|
-
class
|
|
167
|
+
class GameBodyPart{{
|
|
135
168
|
constructor(){{
|
|
136
169
|
}}
|
|
137
170
|
}};
|
|
138
|
-
|
|
171
|
+
class GameAreaEffect{{
|
|
172
|
+
constructor(){{
|
|
173
|
+
}}
|
|
174
|
+
}};
|
|
175
|
+
const GameScoreCollector = GameStructureSpawn;
|
|
139
176
|
import("game/prototypes")
|
|
140
|
-
.then((module) => {{ const
|
|
141
|
-
.catch((error) => {{ }});
|
|
177
|
+
.then((module) => {{ const GameFlag = module.Flag; }})
|
|
178
|
+
.catch((error) => {{ const GameFlag = undefined; }});
|
|
142
179
|
""",
|
|
143
180
|
}
|
|
144
|
-
ARENA_IMPORTS_NOT_BLUE = ""
|
|
145
|
-
ARENA_IMPORTS_NOT_BLUE1 = """
|
|
146
|
-
import { StructureTower } from 'game/prototypes'
|
|
147
|
-
"""
|
|
148
181
|
|
|
149
182
|
|
|
150
183
|
class Compiler_Utils(Compiler_Const):
|
|
@@ -352,6 +385,18 @@ class Compiler_Utils(Compiler_Const):
|
|
|
352
385
|
jsimps.append('./' + '.'.join(rel_path_nodes) + '.js')
|
|
353
386
|
return jsimps
|
|
354
387
|
|
|
388
|
+
# ---------- 自定义函数 ---------- #
|
|
389
|
+
@staticmethod
|
|
390
|
+
def stage_recursive_replace(content:str) -> str:
|
|
391
|
+
"""
|
|
392
|
+
替换'@recursive'为'@recursive(<fname>)', 其中<fname>为被装饰器标记的函数名 |
|
|
393
|
+
Replace '@recursive' with '@recursive(<fname>)', where <fname> is the name of the decorated function.
|
|
394
|
+
|
|
395
|
+
@\s*recursive\s+def\s+([^\s\(]+)
|
|
396
|
+
"""
|
|
397
|
+
return re.sub(r'@\s*recursive(\s+def\s+)([^\s\(]+)', r'@recursive("\2")\1\2', content)
|
|
398
|
+
|
|
399
|
+
|
|
355
400
|
|
|
356
401
|
class CompilerBase(Compiler_Utils):
|
|
357
402
|
|
|
@@ -562,6 +607,14 @@ class Compiler(CompilerBase):
|
|
|
562
607
|
with open(fpath, 'w', encoding='utf-8') as f:
|
|
563
608
|
f.write(new_content)
|
|
564
609
|
|
|
610
|
+
# ------------------------------------ 自定义 ------------------------------------ #
|
|
611
|
+
# 调用stage_recursive_replace
|
|
612
|
+
for fpath in py_fpath:
|
|
613
|
+
content = self.auto_read(fpath)
|
|
614
|
+
content = self.stage_recursive_replace(content)
|
|
615
|
+
with open(fpath, 'w', encoding='utf-8') as f:
|
|
616
|
+
f.write(content)
|
|
617
|
+
|
|
565
618
|
core.lprint(GREEN.format('[2/6]'), LOC_DONE, " ", LOC_PREPROCESSING_FINISH, sep="", head="\r", ln=config.language)
|
|
566
619
|
return _imports, _js_imports, _pre_sort_, _pre_define_, _js_replace_
|
|
567
620
|
|
|
@@ -696,8 +749,6 @@ class Compiler(CompilerBase):
|
|
|
696
749
|
"""
|
|
697
750
|
arena_name = const.ARENA_NAMES.get(config.arena, const.ARENA_NAMES['green']) # like green -> spawn_and_swamp
|
|
698
751
|
self.TOTAL_INSERT_AT_HEAD += self.ARENA_IMPORTS_GETTER[arena_name]() # add arena imports
|
|
699
|
-
if config.arena != "blue":
|
|
700
|
-
self.TOTAL_INSERT_AT_HEAD += self.ARENA_IMPORTS_NOT_BLUE
|
|
701
752
|
total_js = f"const __VERSION__ = '{const.VERSION}';\nconst __PYTHON_VERSION__ = '{python_version_info}';" + self.TOTAL_INSERT_AT_HEAD + f"\nexport var LANGUAGE = '{config.language}';\n"
|
|
702
753
|
|
|
703
754
|
core.lprint(WAIT, LOC_GENERATING_TOTAL_MAIN_JS, end="", ln=config.language)
|
pyscreeps_arena/core/const.py
CHANGED
pyscreeps_arena/project.7z
CHANGED
|
Binary file
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
pyscreeps_arena/__init__.py,sha256=
|
|
1
|
+
pyscreeps_arena/__init__.py,sha256=aQvVULggzXzf3INx0Rrlozdk8Aoxe01lU7b5xytK678,862
|
|
2
2
|
pyscreeps_arena/build.py,sha256=DQeGLnID2FjpsWTbnqwt2cOp28olWK68U67bfbFJSOU,177
|
|
3
|
-
pyscreeps_arena/compiler.py,sha256=
|
|
3
|
+
pyscreeps_arena/compiler.py,sha256=FakYyCZuGGxwarF_K700u9pVreZzdw-p72-m8uypzps,44042
|
|
4
4
|
pyscreeps_arena/localization.py,sha256=gBbrNybIJAHlkzeD6maF-ie6RKSwPBbnCNzg_1ge8-c,5656
|
|
5
|
-
pyscreeps_arena/project.7z,sha256=
|
|
5
|
+
pyscreeps_arena/project.7z,sha256=crcLRbbeGLjgy0wQul1vvwfKoy0Chz3lew5m0f8hgz8,80026
|
|
6
6
|
pyscreeps_arena/core/__init__.py,sha256=qoP_rx1TpbDLJoTm5via4XPwEPaV1FXr1SYvoVoHGms,41
|
|
7
7
|
pyscreeps_arena/core/basic.py,sha256=DFvyDTsTXf2bQtnS9s254TrkshvRwajaHcvTyVvJyqw,2790
|
|
8
8
|
pyscreeps_arena/core/config.py,sha256=U38Z-GiIXPSiAsPKKmOw52AS35Q_tP018H1VUSX6APU,535
|
|
9
|
-
pyscreeps_arena/core/const.py,sha256=
|
|
9
|
+
pyscreeps_arena/core/const.py,sha256=nky-fIzQcWWIT3ccRg-9aviCBNiC2BygaYyyw5GqPMY,552
|
|
10
10
|
pyscreeps_arena/core/core.py,sha256=3Nty8eLKPNgwnYk_sVNBPrWuKxBXI2od8nfEezsEAZQ,5157
|
|
11
11
|
pyscreeps_arena/core/main.py,sha256=-FNSOEjksNlDfCbUqsjtPSUW8vT3qxEdfzXqT5Tdsik,170
|
|
12
12
|
pyscreeps_arena/core/utils.py,sha256=N9OOkORvrqnJakayaFp9qyS0apWhB9lBK4xyyYkhFdo,215
|
|
13
|
-
pyscreeps_arena-0.
|
|
14
|
-
pyscreeps_arena-0.
|
|
15
|
-
pyscreeps_arena-0.
|
|
16
|
-
pyscreeps_arena-0.
|
|
17
|
-
pyscreeps_arena-0.
|
|
13
|
+
pyscreeps_arena-0.4a0.dist-info/METADATA,sha256=gdIKdN3rM9OAVBGud5q_MENg6ffGiyhdBa9Nlj--LkI,2079
|
|
14
|
+
pyscreeps_arena-0.4a0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
15
|
+
pyscreeps_arena-0.4a0.dist-info/entry_points.txt,sha256=mLTkJAsgPBEmFkrxNoo3dvb0_dAzSn9jf4Wh09PjdVU,106
|
|
16
|
+
pyscreeps_arena-0.4a0.dist-info/top_level.txt,sha256=l4uLyMR2NOy41ngBMh795jOHTFk3tgYKy64-9cgjVng,16
|
|
17
|
+
pyscreeps_arena-0.4a0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|