-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.mjs
131 lines (110 loc) · 4.32 KB
/
main.mjs
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
//The purpose of this main file is to run any common functions or imports that all
//arenas will need, and then call the appropriate arena code to run arena specific code.
//Relatively few edits should go in this file other than pointing to new arenas or
//adding additional shared functionality.
//This simply imports all available objects from the specified directory and
//places them in global scope to reduce required code to call built-in functions
//Importing and placing in global here makes these functions and objects
//available in all subsequently imported code (so you dont have to worry about imports in each module)
import * as prototypes from 'game/prototypes';
for (let globalKey in prototypes) { global[globalKey] = prototypes[globalKey];}
import * as constants from 'game/constants';
for (let globalKey in constants) { global[globalKey] = constants[globalKey];}
import * as specConstants from 'arena/constants';
for (let globalKey in specConstants) { global[globalKey] = specConstants[globalKey];}
import * as utils from 'game/utils';
for (let globalKey in utils) { global[globalKey] = utils[globalKey];}
import * as pathing from 'game/path-finder';
for (let globalKey in pathing) { global[globalKey] = pathing[globalKey];}
import * as arenaConstants from 'arena';
for (let globalKey in arenaConstants) { global[globalKey] = arenaConstants[globalKey];}
import { arenaInfo } from '/game';
import { Visual } from 'game/visual';
global.PVisual = new Visual(1,true);
global.TVisual = new Visual(2,false);
//these could be placed behind container objects to reduce global polution
import './SharedModules/generalGlobals.mjs';
import './SharedModules/generalVisuals.mjs';
import './SharedModules/generalMovement.mjs';
import './SharedModules/generalSpawn.mjs';
import './SharedModules/generalCombat.mjs';
//specific arena imports
import{ctf_basic_main} from './BasicCaptureTheFlag/main_ctf1.mjs';
import{sas_basic_main} from './BasicSpawnAndSwamp/main_sas1.mjs';
import{cac_basic_main} from './BasicCollectAndControl/main_cac1.mjs';
//non-arena specific roles (if any)
import{scout} from './SharedModules/CommonRoles/Scout.mjs'
import{healer} from './SharedModules/CommonRoles/Healer.mjs'
import{ranger} from './SharedModules/CommonRoles/Ranger.mjs'
import{mele} from './SharedModules/CommonRoles/Mele.mjs'
global.ROLES = {
scout,
healer,
ranger,
mele
};
export function loop() {
console.log('-------------------tick: '+getTicks());
//console.log(JSON.stringify(arenaInfo));
TVisual = new Visual(1,false); //I do not know if this is how they intend this to be used tbh...
if(getTicks()===1) //initialization stuff (you get extra processing power on first tick)
{
console.log('initializing...');
}
try
{
updateGlobalSearches();
GeneralSpawn.updateSpawning();
CustomCosts.resetStashedCostMatricies();
}
catch(err)
{
console.log('top loop utilities error');
console.log(err.stack);
}
try
{
if(arenaInfo.name === "Capture the Flag" && arenaInfo.level === 1)
{
console.log('ctf lvl 1');
ctf_basic_main();
}
else if(arenaInfo.name === "Spawn and Swamp" && arenaInfo.level === 1)
{
console.log('sas lvl 1');
sas_basic_main();
}
else if(arenaInfo.name === "Collect and Control" && arenaInfo.level === 1)
{
console.log('cac lvl 1');
cac_basic_main();
}
}
catch(err)
{
console.log('main loop error');
console.log(err.stack);
}
//run creeps (all arenas have creeps, so may as well call them here). I use memory.type to describe them, but there are many ways to do the same
MY_CREEPS.forEach(creep => {
if(!creep.memory)
{
console.log('confused creep: '+JSON.stringify(creep));
return;
}
if(findInRange(creep,MY_SPAWNS,0).length>0){return;} //creep spawning
try
{
ROLES[creep.memory.type].run(creep);
}
catch(err)
{
console.log('creep run error: '+creep.memory.type);
console.log(err.stack);
}
});
let cpuUsed = getCpuTime();
let limit = (getTicks() === 1) ? arenaInfo.cpuTimeLimitFirstTick : arenaInfo.cpuTimeLimit;
let usedRatio = cpuUsed / limit;
console.log('CPU: '+ Math.floor(usedRatio*100)+' %');
}