Skip to content

Commit

Permalink
Const correctness, stylistic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
endrift committed Mar 14, 2011
1 parent ab40619 commit b63b5a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
13 changes: 7 additions & 6 deletions ai/AI.cpp
Expand Up @@ -48,23 +48,23 @@ void AI::set_logic(const GameLogic* logic) {
m_logic = logic;
}

const GameLogic* AI::get_logic() {
const GameLogic* AI::get_logic() const {
return m_logic;
}

void AI::set_own_player(const Player* player) {
m_player = player;
}

const Player* AI::get_own_player() {
const Player* AI::get_own_player() const {
return m_player;
}

void AI::set_other_player(const Player* other_player) {
m_other_player = other_player;
}

const Player* AI::get_other_player() {
const Player* AI::get_other_player() const {
return m_other_player;
}

Expand Down Expand Up @@ -148,7 +148,7 @@ float AI::gun_angle_to_player(const Player* player, const Player* other) const {
return fabs(wanted_angle - curr_aim);
}

float AI::time_to_impact(const Player* player) {
float AI::time_to_impact(const Player* player) const {
const b2World* world = m_logic->get_world();

if (world == NULL || grabbing_wall(player)) {
Expand Down Expand Up @@ -204,13 +204,14 @@ SparseIntersectMap* AI::get_map_graph() {
}

void AI::initialize_map_grapher() {
// NOTE: Const cast here is necessary because MapGrapher can only work
// with a non-const b2World for now, due to b2World's GetBodyList() method.
// This is fixed in Box2D's trunk, but not in any released version yet
b2World* world = const_cast<b2World*>(m_logic->get_world());

if (world == NULL) {
return;
}
// NOTE: Const cast here is necessary because MapGrapher can only work
// with a non-const b2World for now, due to b2World's GetBodyList() method.
m_grapher.load_map(m_logic, world);

m_pathfinder.set_graph(get_map_graph());
Expand Down
22 changes: 11 additions & 11 deletions ai/AI.hpp
Expand Up @@ -41,13 +41,13 @@ namespace LM {
class AI {
private:
struct RayCastResult {
PhysicsObject* start_object; // The object (if any) where this ray started
b2Vec2 ray_start; // The starting point of the ray cast
float ray_direction; // The angle (in radians) at which the ray was cast
b2Vec2 ray_end; // The maximum point on the ray
PhysicsObject* closest_object; // The closest object
float shortest_dist; // The closest hit-point on that object
b2Vec2 hit_point; // The point where the ray hit
PhysicsObject* start_object; // The object (if any) where this ray started
b2Vec2 ray_start; // The starting point of the ray cast
float ray_direction; // The angle (in radians) at which the ray was cast
b2Vec2 ray_end; // The maximum point on the ray
PhysicsObject* closest_object; // The closest object
float shortest_dist; // The closest hit-point on that object
b2Vec2 hit_point; // The point where the ray hit
};

const GameLogic* m_logic;
Expand Down Expand Up @@ -80,13 +80,13 @@ namespace LM {
virtual AimReason get_aim_reason();

void set_logic(const GameLogic* logic);
const GameLogic* get_logic();
const GameLogic* get_logic() const;

void set_own_player(const Player* player);
const Player* get_own_player();
const Player* get_own_player() const;

void set_other_player(const Player* other_player);
const Player* get_other_player();
const Player* get_other_player() const;

// Begin methods used to get various data that can be passed to the Fuzzy Logic system.

Expand All @@ -111,7 +111,7 @@ namespace LM {

// Distance to nearest object that could be hit by the player divided by the player's velocity
// Note: if the object that could be hit is moving, this will not check whether it will actually hit
float time_to_impact(const Player* player);
float time_to_impact(const Player* player) const;

// Distance to the player/gate (game units, not physics), if it can be seen, or max float value if not.
float can_see_player(const Player* player, const Player* other_player, float max_radius = -1);
Expand Down

0 comments on commit b63b5a8

Please sign in to comment.