rendered paste bodyIndex: src/object/physical_obj.cpp
===================================================================
--- src/object/physical_obj.cpp (revision 8450)
+++ src/object/physical_obj.cpp (working copy)
@@ -649,8 +649,9 @@
FOR_ALL_LIVING_CHARACTERS(team,character) {
// We check both objet if one overlapse the other
if (&(*character) != this && !IsOverlapping(&(*character)) &&
- !character->IsOverlapping(this) && character->GetTestRect().Intersect(rect))
+ !character->IsOverlapping(this) && Intersect(&(*character), rect)) {
return (PhysicalObj*) &(*character);
+ }
}
}
@@ -658,16 +659,43 @@
FOR_EACH_OBJECT(it) {
PhysicalObj * object=*it;
// We check both objet if one overlapse the other
- if (object != this && !IsOverlapping(object) && !object->IsOverlapping(this) &&
- object->m_collides_with_objects && object->GetTestRect().Intersect(rect)) {
- if (!m_is_character || object->m_collides_with_characters)
- return object;
- }
+ if (!m_is_character || object->m_collides_with_characters)
+ if (object != this && !IsOverlapping(object) && !object->IsOverlapping(this) &&
+ object->m_collides_with_objects && Intersect(object, rect)) {
+ return object;
+ }
}
}
return NULL;
}
+inline bool PhysicalObj::Intersect(const PhysicalObj *object, const Rectanglei & rect) const
+{
+ int obj_width = object->m_width - object->m_test_right - object->m_test_left;
+ obj_width = !obj_width ? 1 : obj_width;
+ Rectanglei obj_rect(object->GetX() + object->m_test_left, 1, obj_width, 1);
+
+ int obj_test_left = obj_rect.GetTopLeftPoint().x;
+ int obj_test_right = obj_rect.GetBottomRightPoint().x;
+ int test_left = rect.GetTopLeftPoint().x ;
+ int test_right = rect.GetBottomRightPoint().x;
+
+ if (!((obj_test_right < test_left) || (obj_test_left > test_right))) {
+ int obj_height = object->m_height - object->m_test_bottom - object->m_test_top;
+ obj_height = !obj_height ? 1 : obj_height;
+ obj_rect.SetPositionY(object->GetY() + object->m_test_top);
+ obj_rect.SetSizeY(obj_height);
+ int obj_test_top = obj_rect.GetTopLeftPoint().y;
+ int obj_test_bottom = obj_rect.GetBottomRightPoint().y;
+ int test_top = rect.GetTopLeftPoint().y;
+ int test_bottom = rect.GetBottomRightPoint().y;
+
+ if (!((obj_test_top > test_bottom) || (obj_test_bottom < test_top)))
+ return true;
+ }
+ return false;
+}
+
bool PhysicalObj::FootsInVacuumXY(const Point2i &position) const
{
if (IsOutsideWorldXY(position)) {
Index: src/object/physical_obj.h
===================================================================
--- src/object/physical_obj.h (revision 8450)
+++ src/object/physical_obj.h (working copy)
@@ -130,6 +130,8 @@
height = !height ? 1 : height;
return Rectanglei(GetX() + m_test_left, GetY() + m_test_top, width, height);
}
+
+ inline bool Intersect(const PhysicalObj* object, const Rectanglei & position) const;
int GetTestWidth() const { return m_width -m_test_left -m_test_right; };
int GetTestHeight() const { return m_height -m_test_top -m_test_bottom; };