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
pub mod cpu {
use std::collections;
use constants::ReturnCode;
get_from_js!(limit -> { Game.cpu.limit } -> f64);
get_from_js!(tick_limit -> { Game.cpu.tickLimit } -> f64);
get_from_js!(bucket -> { Game.cpu.bucket } -> f64);
get_from_js!(shard_limits -> { Game.cpu.shardLimits } -> collections::HashMap<String, f64>);
get_from_js!(get_used -> { Game.cpu.getUsed() } -> f64);
get_from_js!(set_shard_limits(limits: collections::HashMap<String, f32>) -> {
Game.cpu.setShardLimits(@{limits})
} -> ReturnCode);
}
pub mod map {
use stdweb;
use {RoomPosition, Terrain};
get_from_js!(describe_exits(room_name: &str) -> {
Game.cpu.describeExits(@{room_name})
} -> stdweb::Object);
get_from_js!(get_terrain_at(pos: &RoomPosition) -> {
__terrain_type_str_to_num(Game.map.getTerrainAt(@{pos.as_ref()}))
} -> Terrain);
get_from_js!(get_world_size -> {
Game.map.getWorldSize()
} -> i32);
get_from_js!(is_room_available(room_name: &str) -> {
Game.map.isRoomAvailable(@{room_name})
} -> bool);
}
macro_rules! game_map_access {
($mod_name:ident, $type:path, $js_inner:expr) => (
pub mod $mod_name {
use objects;
get_from_js!(keys -> { Object.keys($js_inner) } -> Vec<String>);
get_from_js!(values -> { Object.values($js_inner) } -> Vec<$type>);
get_from_js!(get(name: &str) -> { $js_inner[@{name}]} -> Option<$type>);
}
);
($(
($mod:ident, $type:path, $js:expr)
),* $(,)*) => {
$(
game_map_access!($mod, $type, $js);
)*
};
}
game_map_access! {
(construction_sites, objects::ConstructionSite, Game.constructionSites),
(creeps, objects::Creep, Game.creeps),
(flags, objects::Flag, Game.flags),
(rooms, objects::Room, Game.rooms),
(spawns, objects::StructureSpawn, Game.spawns),
(structures, objects::Structure, Game.structures),
}
get_from_js!(time -> { Game.time } -> u32);