Skip to content

Commit

Permalink
added solid dimensions and made pato have solid area
Browse files Browse the repository at this point in the history
  • Loading branch information
davewx7 committed Oct 24, 2009
1 parent 23bb696 commit ddff1a9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions data/objects/npcs/pato_npc.cfg
Expand Up @@ -5,6 +5,8 @@
body_harmful=no
hitpoints=1
zorder=-1
solid_area=16,12,32,39
solid_dimensions=npc
on_create="animation('stand')"
on_end_stand_anim="[set('facing', if(level.player.x < x, -1, 1)), animation('stand')]"
on_interact="speech_dialog(level.player, ['Whats new?'],
Expand Down
1 change: 1 addition & 0 deletions data/objects/playable/frogatto_playable.cfg
Expand Up @@ -7,6 +7,7 @@
springiness=100
friction=1000
solid_area=8,8,24,30
solid_dimensions=player
vehicle=false
body_harmful=no

Expand Down
4 changes: 4 additions & 0 deletions src/collision_utils.cpp
Expand Up @@ -77,6 +77,10 @@ bool entity_collides(level& lvl, const entity& e, MOVE_DIRECTION dir, collision_

bool entity_collides_with_entity(const entity& e, const entity& other, const std::string** area_id, const std::string** other_area_id)
{
if((e.solid_dimensions()&other.solid_dimensions()) == 0) {
return false;
}

const rect our_rect = e.solid_rect();
const rect other_rect = other.solid_rect();

Expand Down
4 changes: 4 additions & 0 deletions src/custom_object.cpp
Expand Up @@ -55,6 +55,8 @@ custom_object::custom_object(wml::const_node_ptr node)
standing_on_prev_x_(INT_MIN), standing_on_prev_y_(INT_MIN),
can_interact_with_(false), fall_through_platforms_(0)
{
set_solid_dimensions(type_->solid_dimensions());

wml::const_node_ptr tags_node = node->get_child("tags");
if(tags_node) {
tags_ = new game_logic::map_formula_callable(node->get_child("tags"));
Expand Down Expand Up @@ -127,6 +129,8 @@ custom_object::custom_object(const std::string& type, int x, int y, bool face_ri
cycle_(0),
loaded_(false), fall_through_platforms_(0)
{
set_solid_dimensions(type_->solid_dimensions());

for(std::map<std::string, variant>::const_iterator i = type_->variables().begin(); i != type_->variables().end(); ++i) {
if(!vars_->contains(i->first)) {
vars_->add(i->first, i->second);
Expand Down
25 changes: 24 additions & 1 deletion src/custom_object_type.cpp
Expand Up @@ -16,6 +16,20 @@ std::map<std::string, std::string> object_file_paths, prototype_file_paths;

typedef std::map<std::string, const_custom_object_type_ptr> object_map;
object_map cache;

int get_solid_dimension_id(const std::string& key) {
static std::map<std::string, int> dims;
static int next_id = 0;

std::map<std::string, int>::const_iterator itor = dims.find(key);
if(itor != dims.end()) {
return itor->second;
}

dims[key] = next_id;
return next_id++;
}

}

const_custom_object_type_ptr custom_object_type::get(const std::string& id)
Expand Down Expand Up @@ -173,8 +187,17 @@ custom_object_type::custom_object_type(wml::const_node_ptr node)
teleport_offset_y_(wml::get_int(node, "teleport_offset_y")),
solid_(solid_info::create(node)),
platform_(solid_info::create_platform(node)),
has_solid_(solid_ || use_image_for_collisions_)
has_solid_(solid_ || use_image_for_collisions_),
solid_dimensions_(has_solid_ ? 0xFFFFFFFF : 0)
{
if(node->has_attr("solid_dimensions")) {
solid_dimensions_ = 0;
foreach(const std::string& key, util::split(node->attr("solid_dimensions"))) {
solid_dimensions_ = solid_dimensions_|(1 << get_solid_dimension_id(key));
}

}

if(node->has_attr("functions")) {
object_functions_.reset(new game_logic::function_symbol_table);
object_functions_->set_backup(&get_custom_object_functions_symbol_table());
Expand Down
4 changes: 4 additions & 0 deletions src/custom_object_type.hpp
Expand Up @@ -103,6 +103,8 @@ class custom_object_type
//true if the object can ever be solid or standable
bool has_solid() const { return has_solid_; }

unsigned int solid_dimensions() const { return solid_dimensions_; }

private:
std::string id_;
int hitpoints_;
Expand Down Expand Up @@ -162,6 +164,8 @@ class custom_object_type

//variable which is true if the object is ever solid or standable
bool has_solid_;

unsigned int solid_dimensions_;
};

#endif
5 changes: 3 additions & 2 deletions src/entity.cpp
Expand Up @@ -17,15 +17,16 @@ entity::entity(wml::const_node_ptr node)
face_right_(wml::get_bool(node, "face_right")),
upside_down_(wml::get_bool(node, "upside_down", false)),
group_(wml::get_int(node, "group", -1)),
id_(-1), respawn_(wml::get_bool(node, "respawn", true))
id_(-1), respawn_(wml::get_bool(node, "respawn", true)),
solid_dimensions_(0)
{
foreach(bool& b, controls_) {
b = false;
}
}

entity::entity(int x, int y, bool face_right)
: x_(x*100), y_(y*100), prev_feet_x_(INT_MIN), prev_feet_y_(INT_MIN), face_right_(face_right), upside_down_(false), group_(-1), id_(-1)
: x_(x*100), y_(y*100), prev_feet_x_(INT_MIN), prev_feet_y_(INT_MIN), face_right_(face_right), upside_down_(false), group_(-1), id_(-1), solid_dimensions_(0)
{
foreach(bool& b, controls_) {
b = false;
Expand Down
6 changes: 6 additions & 0 deletions src/entity.hpp
Expand Up @@ -215,6 +215,8 @@ class entity : public game_logic::formula_callable

virtual void set_level(level* lvl) {}

unsigned int solid_dimensions() const { return solid_dimensions_; }

protected:

bool control_status(controls::CONTROL_ITEM ctrl) const { return controls_[ctrl]; }
Expand All @@ -229,6 +231,8 @@ class entity : public game_logic::formula_callable

void set_editor_info(const_editor_entity_info_ptr p) { editor_info_ = p; }

void set_solid_dimensions(unsigned int dim) { solid_dimensions_ = dim; }

private:
virtual void control(const level& lvl) = 0;

Expand All @@ -248,6 +252,8 @@ class entity : public game_logic::formula_callable

bool respawn_;

unsigned int solid_dimensions_;

const_editor_entity_info_ptr editor_info_;

current_generator_ptr current_generator_;
Expand Down

0 comments on commit ddff1a9

Please sign in to comment.