--- src/character/body.cpp | 18 +++++++----------- src/character/body.h | 3 +-- src/character/character.cpp | 12 +++++++++--- src/character/character.h | 3 ++- src/weapon/airhammer.cpp | 6 ++++-- src/weapon/baseball.cpp | 5 ++++- src/weapon/flamethrower.cpp | 3 ++- src/weapon/grapple.cpp | 32 +++++++++++++++----------------- src/weapon/parachute.cpp | 6 +++++- src/weapon/slap.cpp | 4 +++- src/weapon/submachine_gun.cpp | 3 ++- src/weapon/syringe.cpp | 5 ++++- src/weapon/weapon.cpp | 35 ++++++++++++++++++++++------------- src/weapon/weapon_launcher.cpp | 18 +++++++++++------- 14 files changed, 91 insertions(+), 62 deletions(-)
diff --git a/src/character/body.cpp b/src/character/body.cpp index 144bb0a..7bfa3ec 100644 --- a/src/character/body.cpp +++ b/src/character/body.cpp @@ -49,7 +49,6 @@ Body::Body(const xmlNode* xml, const std::string& main_folder): previous_clothe(NULL), previous_mvt(NULL), weapon_member(new WeaponMember()), - weapon_pos(0,0), last_refresh(0), walk_events(0), main_rotation_rad(0), @@ -164,7 +163,6 @@ Body::Body(const Body& _body): previous_clothe(NULL), previous_mvt(NULL), weapon_member(new WeaponMember()), - weapon_pos(0,0), last_refresh(0), walk_events(0), main_rotation_rad(0), @@ -462,20 +460,18 @@ std::string Body::GetFrameLoop() const return std::string(str); } -void Body::UpdateWeaponPosition(const Point2i& _pos) +void Body::GetRelativeHandPosition(Point2i& result) const { - // update the weapon position - if (direction == DIRECTION_RIGHT) - weapon_pos = weapon_member->GetPos(); - else - weapon_pos = Point2i(GetSize().x - weapon_member->GetPos().x,weapon_member->GetPos().y); - weapon_pos += _pos; + if (direction == DIRECTION_RIGHT) { + result = weapon_member->GetPos(); + } else { + result.x = GetSize().x - weapon_member->GetPos().x; + result.y = weapon_member->GetPos().y; + } } void Body::DrawWeaponMember(const Point2i& _pos) { - UpdateWeaponPosition(_pos); - weapon_member->Draw(_pos, _pos.x + GetSize().x/2, int(direction)); } diff --git a/src/character/body.h b/src/character/body.h index 3d50340..df025df 100644 --- a/src/character/body.h +++ b/src/character/body.h @@ -80,7 +80,6 @@ class Body // For weapon position handling Member* weapon_member; - Point2i weapon_pos; uint last_refresh; // Time elapsed since last refresh int walk_events; @@ -132,7 +131,7 @@ public: std::string GetFrameLoop() const; void GetTestRect(uint &l, uint &r, uint &t, uint &b) const; const BodyDirection_t &GetDirection() const { return direction; }; - const Point2i &GetHandPosition() const { return weapon_pos; }; + void GetRelativeHandPosition(Point2i& result) const; uint GetMovementDuration() const; uint GetFrame() const { return current_frame; }; uint GetFrameCount() const; diff --git a/src/character/character.cpp b/src/character/character.cpp index 5ccd9f6..5345ec0 100644 --- a/src/character/character.cpp +++ b/src/character/character.cpp @@ -530,7 +530,6 @@ void Character::DoShoot() MSG_DEBUG("weapon.shoot", "-> begin at time %u", Time::GetInstance()->Read()); SetMovementOnce("weapon-" + ActiveTeam().GetWeapon().GetID() + "-end-shoot"); body->Build(); // Refresh the body - body->UpdateWeaponPosition(GetPosition()); damage_stats->OneMoreShot(); ActiveTeam().AccessWeapon().Shoot(); MSG_DEBUG("weapon.shoot", "<- end"); @@ -897,8 +896,15 @@ bool Character::IsActiveCharacter() const } // Hand position -const Point2i & Character::GetHandPosition() const { - return body->GetHandPosition(); +void Character::GetHandPosition(Point2i & result) const +{ + GetRelativeHandPosition(result); + result += GetPosition(); +} + +void Character::GetRelativeHandPosition(Point2i & result) const +{ + body->GetRelativeHandPosition(result); } double Character::GetFiringAngle() const { diff --git a/src/character/character.h b/src/character/character.h index 372a32d..4e7ad28 100644 --- a/src/character/character.h +++ b/src/character/character.h @@ -221,7 +221,8 @@ public: bool IsSameAs(const Character& other) const { return (GetName() == other.GetName()); } void SetCustomName(const std::string name); // Hand position - const Point2i & GetHandPosition() const; + void GetHandPosition(Point2i & result) const; + void GetRelativeHandPosition(Point2i & result) const; // Damage report const DamageStatistics* GetDamageStats() const { return damage_stats; }; diff --git a/src/weapon/airhammer.cpp b/src/weapon/airhammer.cpp index 3dc3528..905286d 100644 --- a/src/weapon/airhammer.cpp +++ b/src/weapon/airhammer.cpp @@ -111,8 +111,10 @@ bool Airhammer::p_Shoot() } // Compute point coordinates - y = ActiveCharacter().GetHandPosition().y + range; - x = ActiveCharacter().GetHandPosition().x; + Point2i hand_position; + ActiveCharacter().GetHandPosition(hand_position); + y = hand_position.y + range; + x = hand_position.x; FOR_ALL_LIVING_CHARACTERS(team, character) if (&(*character) != &ActiveCharacter()) diff --git a/src/weapon/baseball.cpp b/src/weapon/baseball.cpp index 1aa5043..d70dc35 100644 --- a/src/weapon/baseball.cpp +++ b/src/weapon/baseball.cpp @@ -79,7 +79,10 @@ bool Baseball::p_Shoot() // Compute point coordinates Point2i relative_pos(static_cast<int>(rayon * cos(angle)), static_cast<int>(rayon * sin(angle)) ); - Point2i pos_to_check = ActiveCharacter().GetHandPosition() + relative_pos; + + Point2i hand_position; + ActiveCharacter().GetHandPosition(hand_position); + Point2i pos_to_check = hand_position + relative_pos; FOR_ALL_LIVING_CHARACTERS(team, character) if (&(*character) != &ActiveCharacter()) diff --git a/src/weapon/flamethrower.cpp b/src/weapon/flamethrower.cpp index 6a05796..61782b4 100644 --- a/src/weapon/flamethrower.cpp +++ b/src/weapon/flamethrower.cpp @@ -156,7 +156,8 @@ bool FlameThrower::p_Shoot() projectile = NULL; ReloadLauncher(); - Point2i pos = ActiveCharacter().GetHandPosition(); + Point2i pos; + ActiveCharacter().GetHandPosition(pos); double angle = - M_PI_2 - ActiveCharacter().GetDirection() * (float)(Time::GetInstance()->Read() % 100) * M_PI_4 / 100.0; particle.AddNow(pos, 1, particle_SMOKE, true, angle, diff --git a/src/weapon/grapple.cpp b/src/weapon/grapple.cpp index ddee84c..8c2f081 100644 --- a/src/weapon/grapple.cpp +++ b/src/weapon/grapple.cpp @@ -202,8 +202,7 @@ bool Grapple::TryAttachRope() // The rope is being launching. Increase the rope length and check // collisions. - Point2i handPos = ActiveCharacter().GetHandPosition(); - pos = handPos; + ActiveCharacter().GetHandPosition(pos); length = cfg().automatic_growing_speed * delta_time / 10; if (length > cfg().max_rope_length) @@ -245,8 +244,9 @@ bool Grapple::TryAddNode(int CurrentSense) Point2d V; Point2i contact_point; double angle, rope_angle; + Point2i handPos; - Point2i handPos = ActiveCharacter().GetHandPosition(); + ActiveCharacter().GetHandPosition(handPos); // Compute distance between hands and rope fixation point. @@ -292,7 +292,8 @@ bool Grapple::TryRemoveNodes(int currentSense) // [RCL]: nodeSense check seems to be useless... either remove node senses at all or // find an example where it is required double currentAngle = ActiveCharacter().GetRopeAngle(); - Point2i mapRopeStart = ActiveCharacter().GetHandPosition(); + Point2i mapRopeStart; + ActiveCharacter().GetHandPosition(mapRopeStart); const int max_nodes_per_turn = 100; // safe value, was used to avoid network congestion int nodes_to_remove = 0; @@ -416,6 +417,7 @@ void Grapple::Draw() { int x, y; double angle, prev_angle; + Point2i handPos; struct CL_Quad {Sint16 x1,x2,x3,x4,y1,y2,y3,y4;} quad; @@ -436,7 +438,7 @@ void Grapple::Draw() prev_angle = angle; // Draw the rope. - Point2i handPos = ActiveCharacter().GetHandPosition(); + ActiveCharacter().GetHandPosition(handPos); x = handPos.x; y = handPos.y; @@ -495,9 +497,8 @@ void Grapple::AttachRope(const Point2i& contact_point) rope_nodes.clear(); // The rope reaches the fixation point. Let's fix it ! - Point2i handPos = ActiveCharacter().GetHandPosition(); - Point2i pos(handPos.x - ActiveCharacter().GetX(), - handPos.y - ActiveCharacter().GetY()); + Point2i pos; + ActiveCharacter().GetRelativeHandPosition(pos); ActiveCharacter().SetPhysFixationPointXY( contact_point.x / PIXEL_PER_METER, @@ -536,12 +537,10 @@ void Grapple::AttachNode(const Point2i& contact_point, double angle, int sense) { - Point2i handPos = ActiveCharacter().GetHandPosition(); - // The rope has collided something... // Add a node on the rope and change the fixation point. - Point2i pos(handPos.x - ActiveCharacter().GetX(), - handPos.y - ActiveCharacter().GetY()); + Point2i pos; + ActiveCharacter().GetRelativeHandPosition(pos); ActiveCharacter().SetPhysFixationPointXY(contact_point.x / PIXEL_PER_METER, contact_point.y / PIXEL_PER_METER, @@ -575,14 +574,13 @@ void Grapple::DetachNode() m_fixation_point = rope_nodes.back().pos ; - Point2i handPos = ActiveCharacter().GetHandPosition(); - int dx = handPos.x - ActiveCharacter().GetX(); - int dy = handPos.y - ActiveCharacter().GetY(); + Point2i pos; + ActiveCharacter().GetRelativeHandPosition(pos); ActiveCharacter().SetPhysFixationPointXY(m_fixation_point.x / PIXEL_PER_METER, m_fixation_point.y / PIXEL_PER_METER, - (double)dx / PIXEL_PER_METER, - (double)dy / PIXEL_PER_METER); + (double)pos.x / PIXEL_PER_METER, + (double)pos.y / PIXEL_PER_METER); } // =========================== Moves management diff --git a/src/weapon/parachute.cpp b/src/weapon/parachute.cpp index dbf5a53..9bbf463 100644 --- a/src/weapon/parachute.cpp +++ b/src/weapon/parachute.cpp @@ -101,7 +101,11 @@ void Parachute::Draw() { if(open) { img->Update(); - img->Draw(ActiveCharacter().GetHandPosition() - Point2i(img->GetWidth()/2,img->GetHeight())); + Point2i position; + ActiveCharacter().GetHandPosition(position); + position.x -= img->GetWidth()/2; + position.y -= img->GetHeight(); + img->Draw(position); } } diff --git a/src/weapon/slap.cpp b/src/weapon/slap.cpp index 42d7388..83cc24c 100644 --- a/src/weapon/slap.cpp +++ b/src/weapon/slap.cpp @@ -106,7 +106,9 @@ bool Slap::p_Shoot (){ // Compute point coordinates Point2i relative_pos(static_cast<int>(radius * cos(angle)), static_cast<int>(radius * sin(angle)) ); - Point2i pos_to_check = ActiveCharacter().GetHandPosition() + relative_pos; + Point2i hand_position; + ActiveCharacter().GetHandPosition(hand_position); + Point2i pos_to_check = hand_position + relative_pos; FOR_ALL_LIVING_CHARACTERS(team, character) if (&(*character) != &ActiveCharacter()) { diff --git a/src/weapon/submachine_gun.cpp b/src/weapon/submachine_gun.cpp index e73541b..533cc81 100644 --- a/src/weapon/submachine_gun.cpp +++ b/src/weapon/submachine_gun.cpp @@ -124,7 +124,8 @@ bool SubMachineGun::p_Shoot() projectile = NULL; ReloadLauncher(); - Point2i pos = ActiveCharacter().GetHandPosition(); + Point2i pos; + ActiveCharacter().GetHandPosition(pos); double angle = - M_PI_2 - ActiveCharacter().GetDirection() * (float)(Time::GetInstance()->Read() % 100) * M_PI_4 / 100.0; particle.AddNow(pos, 1, particle_BULLET, true, angle, diff --git a/src/weapon/syringe.cpp b/src/weapon/syringe.cpp index c498705..5ba0f53 100644 --- a/src/weapon/syringe.cpp +++ b/src/weapon/syringe.cpp @@ -91,7 +91,10 @@ bool Syringe::p_Shoot (){ // Compute point coordinates Point2i relative_pos(static_cast<int>(radius * cos(angle)), static_cast<int>(radius * sin(angle)) ); - Point2i pos_to_check = ActiveCharacter().GetHandPosition() + relative_pos; + Point2i hand_position; + ActiveCharacter().GetHandPosition(hand_position); + Point2i pos_to_check = hand_position + relative_pos; + FOR_ALL_LIVING_CHARACTERS(team, character) if (&(*character) != &ActiveCharacter()) { diff --git a/src/weapon/weapon.cpp b/src/weapon/weapon.cpp index 8d4a756..5c64e36 100644 --- a/src/weapon/weapon.cpp +++ b/src/weapon/weapon.cpp @@ -278,12 +278,16 @@ bool Weapon::Shoot() MSG_DEBUG("weapon.shoot", "Enough ammo"); + #ifdef DEBUG + Point2i hand; + ActiveCharacter().GetHandPosition(hand); MSG_DEBUG("weapon.shoot", "%s Shooting at position:%d,%d (hand: %d,%d)", ActiveCharacter().GetName().c_str(), ActiveCharacter().GetX(), ActiveCharacter().GetY(), - ActiveCharacter().GetHandPosition().GetX(), - ActiveCharacter().GetHandPosition().GetY()); + hand.GetX(), + hand.GetY()); + #endif ActiveCharacter().body->DebugState(); if (!p_Shoot()) return false; m_last_fire_time = Time::GetInstance()->Read(); @@ -402,7 +406,8 @@ void Weapon::PosXY (int &x, int &y) const { if (origin == weapon_origin_HAND) { - Point2i handPos = ActiveCharacter().GetHandPosition(); + Point2i handPos; + ActiveCharacter().GetHandPosition(handPos); y = handPos.y - position.y; if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT) x = handPos.x - position.x; @@ -421,7 +426,8 @@ void Weapon::PosXY (int &x, int &y) const const Point2i Weapon::GetGunHolePosition() const { - const Point2i &pos = ActiveCharacter().GetHandPosition(); + Point2i pos; + ActiveCharacter().GetHandPosition(pos); Point2i hole(pos + hole_delta * Point2i(ActiveCharacter().GetDirection(),1)); double dst = pos.Distance(hole); double angle = pos.ComputeAngle(hole); @@ -600,8 +606,10 @@ void Weapon::Draw(){ #ifdef DEBUG if (IsLOGGING("weapon")) { - Rectanglei rect(ActiveCharacter().GetHandPosition().GetX()-1 - Camera::GetInstance()->GetPositionX(), - ActiveCharacter().GetHandPosition().GetY()-1 - Camera::GetInstance()->GetPositionY(), + Point2i hand; + ActiveCharacter().GetHandPosition(hand); + Rectanglei rect(hand.GetX()-1 - Camera::GetInstance()->GetPositionX(), + hand.GetY()-1 - Camera::GetInstance()->GetPositionY(), 3, 3); @@ -612,8 +620,8 @@ void Weapon::Draw(){ MSG_DEBUG("weapon.handposition", "Position: %d, %d - hand: %d, %d", ActiveCharacter().GetX(), ActiveCharacter().GetY(), - ActiveCharacter().GetHandPosition().GetX(), - ActiveCharacter().GetHandPosition().GetY()); + hand.GetX(), + hand.GetY()); } #endif #ifdef DEBUG_HOLE @@ -632,22 +640,23 @@ void Weapon::Draw(){ void Weapon::DrawWeaponFire() { if (m_weapon_fire == NULL) return; - Point2i pos = ActiveCharacter().GetHandPosition(); - Point2i hole(pos + hole_delta * Point2i(ActiveCharacter().GetDirection(),1)); + Point2i hand; + ActiveCharacter().GetHandPosition(hand); + Point2i hole(hand + hole_delta * Point2i(ActiveCharacter().GetDirection(),1)); if( ActiveCharacter().GetDirection() == DIRECTION_RIGHT) hole = hole - Point2i(0, m_weapon_fire->GetHeight()/2); else hole = hole + Point2i(0, m_weapon_fire->GetHeight()/2); - double dst = pos.Distance(hole); - double angle = pos.ComputeAngle(hole); + double dst = hand.Distance(hole); + double angle = hand.ComputeAngle(hole); angle += ActiveCharacter().GetFiringAngle(); if( ActiveCharacter().GetDirection() == DIRECTION_LEFT) angle -= M_PI; - Point2i spr_pos = pos + Point2i(static_cast<int>(dst * cos(angle)), + Point2i spr_pos = hand + Point2i(static_cast<int>(dst * cos(angle)), static_cast<int>(dst * sin(angle))); m_weapon_fire->SetRotation_HotSpot (Point2i(0,0)); diff --git a/src/weapon/weapon_launcher.cpp b/src/weapon/weapon_launcher.cpp index 4e07232..214e3b8 100644 --- a/src/weapon/weapon_launcher.cpp +++ b/src/weapon/weapon_launcher.cpp @@ -166,13 +166,17 @@ void WeaponProjectile::Shoot(double strength) double angle = ActiveCharacter().GetFiringAngle(); RandomizeShoot(angle, strength); + Point2i hand_position; + ActiveCharacter().GetHandPosition(hand_position); + ActiveCharacter().GetHandPosition(hand_position); MSG_DEBUG("weapon.projectile", "shoot from position %d,%d (size %d, %d) - hand position:%d,%d", - ActiveCharacter().GetX(), - ActiveCharacter().GetY(), - ActiveCharacter().GetWidth(), - ActiveCharacter().GetHeight(), - ActiveCharacter().GetHandPosition().GetX(), - ActiveCharacter().GetHandPosition().GetY()); + ActiveCharacter().GetX(), + ActiveCharacter().GetY(), + ActiveCharacter().GetWidth(), + ActiveCharacter().GetHeight(), + hand_position.GetX(), + hand_position.GetY()); + MSG_DEBUG("weapon.projectile", "shoot with strength:%f, angle:%f, position:%d,%d", strength, angle, GetX(), GetY()); @@ -182,7 +186,7 @@ void WeaponProjectile::Shoot(double strength) // bug #10236 : problem with flamethrower collision detection // Check if the object is colliding something between hand position and gun hole - Point2i hand_position = ActiveCharacter().GetHandPosition() - GetSize() / 2; + hand_position -= GetSize() / 2; Point2i hole_position = launcher->GetGunHolePosition() - GetSize() / 2; Point2d f_hand_position(hand_position.GetX() / PIXEL_PER_METER, hand_position.GetY() / PIXEL_PER_METER); Point2d f_hole_position(hole_position.GetX() / PIXEL_PER_METER, hole_position.GetY() / PIXEL_PER_METER); -- 1.6.0.4 _______________________________________________ Wormux-dev mailing list Wormux-dev@gna.org https://mail.gna.org/listinfo/wormux-dev