-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
September 2018 game update #71
Changes from 5 commits
caf4830
c84e80c
8254d50
30dfbd6
6c25313
22a6c0b
c668487
5f09223
4851cb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,6 +250,9 @@ pub enum Terrain { | |
Plain = 0, | ||
Wall = 1, | ||
Swamp = 2, | ||
SwampWall = 3, | ||
Lava = 4, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this should be necessary? I'm against including if if it doesn't occur just because it forces any consumers of The screeps team has mentioned on slack that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a question of whether you prefer to implement 1:1 the constants or clean-up the API on our end. I'm all for making the usage easier rather than going for 1:1 translation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case I would go for "cleanup", but I think 1:1 would agree here too. We're only ever returning the terrain, never passing it into the game, and the only place it's returned is documented to not return 4. Even though the constant exists, it's documented to never be used? |
||
// Todo: Implement the other masks when lava becomes a thing | ||
} | ||
|
||
impl TryFrom<Value> for Terrain { | ||
|
@@ -267,26 +270,15 @@ impl TryFrom<Value> for Terrain { | |
0 => Terrain::Plain, | ||
1 => Terrain::Wall, | ||
2 => Terrain::Swamp, | ||
// might not need this, but just in case we try | ||
// to decode a game-encoded number and '3' represents swamp + wall | ||
3 => Terrain::Wall, | ||
3 => Terrain::SwampWall, | ||
4 => Terrain::Lava, | ||
x => panic!("unknown terrain encoded integer {}", x), | ||
}, | ||
}; | ||
Ok(v) | ||
} | ||
} | ||
|
||
impl AsRef<str> for Terrain { | ||
fn as_ref(&self) -> &str { | ||
match *self { | ||
Terrain::Plain => "plain", | ||
Terrain::Wall => "wall", | ||
Terrain::Swamp => "swamp", | ||
} | ||
} | ||
} | ||
|
||
/// Internal enum representing each LOOK_* constant. | ||
/// | ||
/// It's recommended to use the constants in the `look` module instead for type safety. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use std::{marker::PhantomData, mem, ops::Range}; | ||
|
||
use serde_json; | ||
use stdweb::Reference; | ||
|
||
use { | ||
|
@@ -8,7 +9,8 @@ use { | |
}, | ||
memory::MemoryReference, | ||
objects::{ | ||
HasPosition, Room, RoomPosition, StructureController, StructureStorage, StructureTerminal, | ||
HasPosition, Room, RoomPosition, RoomTerrain, StructureController, StructureStorage, | ||
StructureTerminal, | ||
}, | ||
pathfinder::CostMatrix, | ||
positions::LocalRoomName, | ||
|
@@ -102,10 +104,19 @@ impl Room { | |
} | ||
} | ||
|
||
pub fn get_event_log(&self) -> Vec<Event> { | ||
let raw_event_log: String = js_unwrap!{@{self.as_ref()}.getEventLog(true)}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fully fix #59 it'd be nice to have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't see the usage, but sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe storing the event log in a segment for further inspection? I could imagine doing this when in a "low cpu available" mode if under attack and an exact replay of events is wanted. There's the room history, but that's not entirely reliable, and the AI itself cannot analyze it. Or an AI could want to use something besides I'm not sure I would do any of these things, but since the JS API does give us this option and it is much cheaper than parsing it, I'd prefer giving that option as well. |
||
serde_json::from_str(&raw_event_log).expect("Malformed Event Log") | ||
} | ||
|
||
pub fn get_position_at(&self, x: u32, y: u32) -> Option<RoomPosition> { | ||
js_unwrap!{@{self.as_ref()}.get_position_at(@{x}, @{y})} | ||
} | ||
|
||
pub fn get_terrain(&self) -> RoomTerrain { | ||
js_unwrap!(@{self.as_ref()}.getTerrain()) | ||
} | ||
|
||
// pub fn look_at(&self, x: u32, y: u32) -> ! { | ||
// unimplemented!() | ||
// } | ||
|
@@ -420,3 +431,120 @@ pub enum Path { | |
} | ||
|
||
js_deserializable!{Path} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
pub struct Event { | ||
#[serde(flatten)] | ||
pub event: EventType, | ||
#[serde(rename = "objectId")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this work as |
||
pub object_id: String, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(tag = "event", content = "data")] | ||
pub enum EventType { | ||
#[serde(rename = "1")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work? I have not tested whether serde equates the string I'd almost want us to include a small unit test to ensure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not tested it. My problem is working on getting those to actually make sense without, but I might have to write a deserializer manually for this one. I had forgotten that integers were a thing in JSON. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is actually being worked on right now: I might wait a few days and see whether this goes anywhere. Still, I'm learning how to manually write a deserializer in the meantime. |
||
Attack(AttackEvent), | ||
#[serde(rename = "2")] | ||
ObjectDestroyed(ObjectDestroyedEvent), | ||
#[serde(rename = "3")] | ||
AttackController, | ||
#[serde(rename = "4")] | ||
Build(BuildEvent), | ||
#[serde(rename = "5")] | ||
Harvest(HarvestEvent), | ||
#[serde(rename = "6")] | ||
Heal(HealEvent), | ||
#[serde(rename = "7")] | ||
Repair(RepairEvent), | ||
#[serde(rename = "8")] | ||
ReserveController(ReserveControllerEvent), | ||
#[serde(rename = "9")] | ||
UpgradeController(UpgradeControllerEvent), | ||
#[serde(rename = "10")] | ||
Exit(ExitEvent), | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct AttackEvent { | ||
pub target_id: String, | ||
pub damage: u32, | ||
pub attack_type: AttackType, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[repr(u32)] | ||
pub enum AttackType { | ||
Melee = 1, | ||
Ranged = 2, | ||
RangedMass = 3, | ||
Dismantle = 4, | ||
HitBack = 5, | ||
Nuke = 6, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
pub struct ObjectDestroyedEvent { | ||
#[serde(rename = "type")] | ||
pub object_type: String, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct BuildEvent { | ||
pub target_id: String, | ||
pub amount: u32, | ||
pub energy_spent: u32, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct HarvestEvent { | ||
pub target_id: String, | ||
pub amount: u32, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct HealEvent { | ||
pub target_id: String, | ||
pub amount: u32, | ||
pub heal_type: HealType, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[repr(u32)] | ||
pub enum HealType { | ||
Melee = 1, | ||
Ranged = 2, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct RepairEvent { | ||
pub target_id: String, | ||
pub amount: u32, | ||
pub energy_spent: u32, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ReserveControllerEvent { | ||
pub amount: u32, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct UpgradeControllerEvent { | ||
pub amount: u32, | ||
pub energy_spent: u32, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ExitEvent { | ||
pub room: String, | ||
pub x: u32, | ||
pub y: u32, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use {constants::Terrain, objects::RoomTerrain}; | ||
|
||
impl RoomTerrain { | ||
pub fn constructor(room_name: &str) -> Self { | ||
js_unwrap!{new Room.Terrain(@{room_name})} | ||
} | ||
|
||
pub fn get(&self, x: u32, y: u32) -> Terrain { | ||
js_unwrap!{@{self.as_ref()}.get(@{x}, @{y})} | ||
} | ||
|
||
pub fn get_raw_buffer(&self) -> Vec<u8> { | ||
js_unwrap!(@{self.as_ref()}.getRawBuffer()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in my comment, I think it should be pretty simple to create the |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is right now I don't see a reason to include this separately from
Wall
.It makes no gameplay difference whether a wall has a swamp underneath it or not, and forcing consumers of
Terrain
to consider that there is a difference seems a bit wrong?o4kapuk has also mentioned on slack that the official server has gone through and replaced all terrain 3 tiles with terrain 1, and that the screeps team is working on a patch for the private server to do a similar thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't know that. Fair enough, I'll remove it.