Skip to content

Commit

Permalink
Merge pull request #221 from rustyscreeps/work-around-undefined-hits
Browse files Browse the repository at this point in the history
Work around undefined hits and hitsMax
  • Loading branch information
daboross authored Aug 15, 2019
2 parents 5c72fcb + e82a5c1 commit ba94980
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,24 @@ pub unsafe trait Withdrawable: RoomObjectProperties {}
/// The reference returned from `AsRef<Reference>::as_ref` must be a valid
/// target for `Creep.attack`.
pub unsafe trait Attackable: RoomObjectProperties {
/// Retrieve this hits of this structure, or `0` if this structure doesn't
/// have a hit count.
///
/// For instance, this retrieves the hitpoints of a `Creep`. Or for a
/// `StructureWall` that's part of a novice area border, this will return
/// `0`.
fn hits(&self) -> u32 {
js_unwrap! { @{self.as_ref()}.hits }
js_unwrap! { @{self.as_ref()}.hits || 0 }
}

/// Retrieve the maximum hits of this structure, or `0` if this structure
/// doesn't have a hit count.
///
/// For instance, this retrieves the maximum full health of a `Creep`. Or
/// for a `StructureWall` that's part of a novice area border, this will
/// return `0`.
fn hits_max(&self) -> u32 {
js_unwrap! { @{self.as_ref()}.hitsMax }
js_unwrap! { @{self.as_ref()}.hitsMax || 0 }
}
}

Expand Down

0 comments on commit ba94980

Please sign in to comment.