2019-12-08 06:20 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000301Spring engineGeneralpublic2006-09-26 22:12
ReporterILMTitan 
Assigned Tojcnossen 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000301: [Patch] Smarter unit behavior for multiple weapons and those with arcs. BUGFIX
DescriptionAs Cydar pointed out, an attack ground order on the sea could cause units to "dance." This fixes that behavior.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon ArcWeaponBugfix.patch (7,181 bytes) 2006-09-24 01:43 -
    Index: rts/Sim/MoveTypes/groundmovetype.cpp
    ===================================================================
    --- rts/Sim/MoveTypes/groundmovetype.cpp	(revision 2271)
    +++ rts/Sim/MoveTypes/groundmovetype.cpp	(working copy)
    @@ -25,6 +25,7 @@
     #include "MoveMath/MoveMath.h"
     #include "Sim/Misc/GeometricObjects.h"
     #include "Sim/Weapons/Weapon.h"
    +#include "Sim/Weapons/WeaponDefHandler.h"
     #include "Game/SelectedUnits.h"
     #include "Rendering/GroundDecalHandler.h"
     #include "ExternalAI/GlobalAIHandler.h"
    @@ -1422,6 +1423,9 @@
     	this->mainHeadingPos = pos;
     	this->useMainHeading = aggressive;
     	if(this->useMainHeading && !this->owner->weapons.empty()){
    +		if(!this->owner->weapons[0]->weaponDef->waterweapon && this->mainHeadingPos.y <= 1){
    +			this->mainHeadingPos.y = 1;
    +		}
     		float3 dir1 = this->owner->weapons.front()->mainDir;
     		dir1.y = 0;
     		dir1.Normalize();
    @@ -1429,15 +1433,42 @@
     		dir2.y = 0;
     		dir2.Normalize();
     		if(dir2 != ZeroVector){
    -			short heading = GetHeadingFromVector(dir2.x,dir2.z) - GetHeadingFromVector(dir1.x,dir1.z);
    +			short heading = GetHeadingFromVector(dir2.x,dir2.z)
    +				- GetHeadingFromVector(dir1.x,dir1.z);
     			if(this->owner->heading != heading
    -			  && !this->owner->weapons.front()->TryTarget(this->mainHeadingPos, true,0)){
    +					&& !(this->owner->weapons.front()->TryTarget(
    +					this->mainHeadingPos, true, 0))){
     				this->progressState = Active;
     			}
     		}
     	}
     }
     
    +void CGroundMoveType::KeepPointingTo(CUnit* unit, float distance, bool aggressive){
    +	this->mainHeadingPos = unit->pos;
    +	this->useMainHeading = aggressive;
    +	if(this->useMainHeading
    +			&& !this->owner->weapons.empty()
    +			&& (this-owner->weapons[0]->weaponDef->waterweapon
    +			|| this->mainHeadingPos.y >= 0)){
    +		float3 dir1 = this->owner->weapons.front()->mainDir;
    +		dir1.y = 0;
    +		dir1.Normalize();
    +		float3 dir2 = this->mainHeadingPos-this->owner->pos;
    +		dir2.y = 0;
    +		dir2.Normalize();
    +		if(dir2 != ZeroVector){
    +			short heading = GetHeadingFromVector(dir2.x,dir2.z)
    +				- GetHeadingFromVector(dir1.x,dir1.z);
    +			if(this->owner->heading != heading
    +					&& !(this->owner->weapons.front()->TryTarget(
    +					this->mainHeadingPos, true, 0))){
    +				this->progressState = Active;
    +			}
    +		}
    +	}
    +}
    +
     /**
     * @brief Orients owner so that weapon[0]'s arc includes mainHeadingPos
     */
    @@ -1450,19 +1481,29 @@
     		dir2.y = 0;
     		dir2.Normalize();
     		if(dir2 != ZeroVector){
    -			short heading = GetHeadingFromVector(dir2.x,dir2.z) - GetHeadingFromVector(dir1.x,dir1.z);
    +			short heading = GetHeadingFromVector(dir2.x,dir2.z)
    +				- GetHeadingFromVector(dir1.x,dir1.z);
    +
     			if(this->progressState == Active && this->owner->heading == heading){
    +				//logOutput.Print("Stop turning");
     				this->owner->cob->Call(COBFN_StopMoving);
     				this->progressState = Done;
     			} else if(this->progressState == Active){
     				this->ChangeHeading(heading);
    +				//logOutput.Print("Test headding: %d,  Real headding: %d", heading,
    +				//	this->owner->heading);
     			} else if(this->progressState != Active
     			  && this->owner->heading != heading
     			  && !this->owner->weapons.front()->TryTarget(this->mainHeadingPos, true,0)){
     				this->progressState = Active;
     				this->owner->cob->Call(COBFN_StartMoving);
     				this->ChangeHeading(heading);
    +				//logOutput.Print("Start Moving");
    +			} else {
    +				//logOutput.Print("No set main headding");
     			}
    +		} else {
    +			//logOutput.Print("Zero Vector");
     		}
     	}
     }
    Index: rts/Sim/MoveTypes/groundmovetype.h
    ===================================================================
    --- rts/Sim/MoveTypes/groundmovetype.h	(revision 2271)
    +++ rts/Sim/MoveTypes/groundmovetype.h	(working copy)
    @@ -31,6 +31,7 @@
     	void ImpulseAdded(void);
     	
     	void KeepPointingTo(float3 pos, float distance, bool aggressive);
    +	void KeepPointingTo(CUnit* unit, float distance, bool aggressive);
     
     	//float baseSpeed;		//Not used
     	//float maxSpeed;		//Moved to CMoveType, by Lars 04-08-23
    Index: rts/Sim/MoveTypes/MoveType.cpp
    ===================================================================
    --- rts/Sim/MoveTypes/MoveType.cpp	(revision 2271)
    +++ rts/Sim/MoveTypes/MoveType.cpp	(working copy)
    @@ -44,3 +44,7 @@
     void CMoveType::LeaveTransport(void)
     {
     }
    +
    +void CMoveType::KeepPointingTo(CUnit* unit, float distance, bool aggressive) {
    +	KeepPointingTo(float3(unit->pos), distance, aggressive);
    +};
    Index: rts/Sim/MoveTypes/MoveType.h
    ===================================================================
    --- rts/Sim/MoveTypes/MoveType.h	(revision 2271)
    +++ rts/Sim/MoveTypes/MoveType.h	(working copy)
    @@ -14,6 +14,7 @@
     	virtual void StartMoving(float3 pos, float goalRadius){};
     	virtual void StartMoving(float3 pos, float goalRadius, float speed){};
     	virtual void KeepPointingTo(float3 pos, float distance, bool aggressive) {};
    +	virtual void KeepPointingTo(CUnit* unit, float distance, bool aggressive);
     	virtual void StopMoving(){};
     	virtual void Idle(unsigned int frames){};
     	virtual void Idle(){};
    Index: rts/Sim/Units/CommandAI/MobileCAI.cpp
    ===================================================================
    --- rts/Sim/Units/CommandAI/MobileCAI.cpp	(revision 2271)
    +++ rts/Sim/Units/CommandAI/MobileCAI.cpp	(working copy)
    @@ -376,13 +376,19 @@
     		}
     		if(orderTarget){
     			//note that we handle aircrafts slightly differently
    -			if((((owner->AttackUnit(orderTarget, c.id==CMD_DGUN) && owner->weapons.size() > 0
    -			  && owner->weapons.front()->range > orderTarget->pos.distance(owner->pos))
    -			  || dynamic_cast<CTAAirMoveType*>(owner->moveType))
    -			  && (owner->pos-orderTarget->pos).Length2D()<owner->maxRange*0.9f)
    -			  || (owner->pos-orderTarget->pos).SqLength2D()<1024){
    +			if((((owner->AttackUnit(orderTarget, c.id==CMD_DGUN)
    +					&& owner->weapons.size() > 0 
    +					&& owner->weapons.front()->range -
    +						owner->weapons.front()->relWeaponPos.Length() >
    +						orderTarget->pos.distance(owner->pos))
    +					|| dynamic_cast<CTAAirMoveType*>(owner->moveType))
    +					&& (owner->pos-orderTarget->pos).Length2D() <
    +						owner->maxRange*0.9f)
    +					|| (owner->pos-orderTarget->pos).SqLength2D()<1024){
     				StopMove();
    -				owner->moveType->KeepPointingTo(orderTarget->pos, min((float)(owner->losRadius*SQUARE_SIZE*2), owner->maxRange*0.9f), true);
    +				owner->moveType->KeepPointingTo(orderTarget,
    +					min((float)(owner->losRadius*SQUARE_SIZE*2),
    +					owner->maxRange*0.9f), true);
     			} else if((orderTarget->pos+owner->posErrorVector*128).distance2D(goalPos) > 10+orderTarget->pos.distance2D(owner->pos)*0.2f){
     				float3 fix=orderTarget->pos+owner->posErrorVector*128;
     				SetGoal(fix,curPos);
    @@ -390,7 +396,10 @@
     		} else {
     			float3 pos(c.params[0],c.params[1],c.params[2]);
     			if((owner->AttackGround(pos,c.id==CMD_DGUN) && owner->weapons.size() > 0
    -			  && (owner->pos-pos).Length()< owner->weapons.front()->range) || (owner->pos-pos).SqLength2D()<1024){
    +					&& (owner->pos-pos).Length() < 
    +						owner->weapons.front()->range -
    +						owner->weapons.front()->relWeaponPos.Length())
    +					|| (owner->pos-pos).SqLength2D()<1024){
     				StopMove();
     				owner->moveType->KeepPointingTo(pos, owner->maxRange*0.9f, true);
     			} else if(pos.distance2D(goalPos)>10){
    
    patch file icon ArcWeaponBugfix.patch (7,181 bytes) 2006-09-24 01:43 +

-Relationships
+Relationships

-Notes

~0000396

jcnossen (reporter)

Patch applied. It seems to work ok now, thanks!
+Notes

-Issue History
Date Modified Username Field Change
2006-09-24 01:43 ILMTitan New Issue
2006-09-24 01:43 ILMTitan File Added: ArcWeaponBugfix.patch
2006-09-26 22:12 jcnossen Status new => resolved
2006-09-26 22:12 jcnossen Resolution open => fixed
2006-09-26 22:12 jcnossen Assigned To => jcnossen
2006-09-26 22:12 jcnossen Note Added: 0000396
+Issue History