2019-12-16 01:16 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000675Spring engineGeneralpublic2007-11-14 20:55
ReporterKDR_11k 
Assigned Toimbaczek 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000675: [patch] BlockShotX can force a retarget
DescriptionThis patch adds a third argument to BlockShotX that, like the second, reacts to being changed in the function itself.

If this argument is changed to true the weapon will avoid the target BlockShotX was called on, i.e. it acts as if the target was in the badTargetCategory: Retarget regularly and greatly reduce their targetting priority.

This is very useful for any script that wants to prevent a weapon from shooting at certain targets without having it lock down completely every time an unwanted target is chosen (because it can't shoot at the target but the weapon keeps aiming at it), e.g. when BlockShotX enforces minimum ranges.
Additional InformationBlockShotX gets called when the list of targets is compiled now to affect the weighting.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon blockTarget.patch (2,057 bytes) 2007-11-10 18:33 -
    Index: Game/GameHelper.cpp
    ===================================================================
    --- Game/GameHelper.cpp	(revision 4750)
    +++ Game/GameHelper.cpp	(working copy)
    @@ -436,6 +436,8 @@
     							value*=0.4f;
     						if((*ui)->category & weapon->badTargetCategory)
     							value*=100;
    +						if (weapon->CobBlockShot(*ui, 1))
    +							value*=150;
     						if(paralyzer && (*ui)->health-(*ui)->paralyzeDamage<(*ui)->maxHealth*0.09f)
     							value*=4;
     						if((*ui)->crashing)
    Index: Sim/Weapons/Weapon.cpp
    ===================================================================
    --- Sim/Weapons/Weapon.cpp	(revision 4750)
    +++ Sim/Weapons/Weapon.cpp	(working copy)
    @@ -191,7 +191,7 @@
     }
     
     
    -inline bool CWeapon::CobBlockShot(const CUnit* targetUnit)
    +bool CWeapon::CobBlockShot(const CUnit* targetUnit, int blockOrAvoid) const
     {
     	if (!cobHasBlockShot) {
     		return false;
    @@ -205,10 +205,11 @@
     	args.push_back(unitID);
     	args.push_back(0); // arg[1], for the return value
     	                   // the default is to not block the shot
    +	args.push_back(0); // arg[2] for return value, 1 means the target is unwanted
     
     	owner->cob->Call(COBFN_BlockShot + weaponNum, args);
     
    -	return !!args[1];
    +	return !!args[1 + blockOrAvoid];
     }
     
     
    @@ -533,6 +534,9 @@
     		if (targetUnit->category & badTargetCategory) {
     			return true;
     		}
    +		else if (CobBlockShot(targetUnit, 1)) {
    +			return true;
    +		}
     	}
     
     	if (gs->frameNum > (lastTargetRetry + 65)) {
    Index: Sim/Weapons/Weapon.h
    ===================================================================
    --- Sim/Weapons/Weapon.h	(revision 4750)
    +++ Sim/Weapons/Weapon.h	(working copy)
    @@ -37,7 +37,7 @@
     	bool TryTargetRotate(CUnit* unit, bool userTarget);
     	bool TryTargetRotate(float3 pos, bool userTarget);
     	bool TryTargetHeading(short heading, float3 pos, bool userTarget, CUnit* unit = 0);
    -	bool CobBlockShot(const CUnit* unit);
    +	bool CobBlockShot(const CUnit* unit, int blockOrAvoid=0) const;
     	void SlowUpdate(bool noAutoTargetOverride);
     	virtual void SlowUpdate();
     	virtual void Update();
    
    patch file icon blockTarget.patch (2,057 bytes) 2007-11-10 18:33 +
  • patch file icon changeTarget.patch (5,620 bytes) 2007-11-10 22:09 -
    Index: Game/GameHelper.cpp
    ===================================================================
    --- Game/GameHelper.cpp	(revision 4750)
    +++ Game/GameHelper.cpp	(working copy)
    @@ -440,6 +440,8 @@
     							value*=4;
     						if((*ui)->crashing)
     							value*=10;
    +						if(weapon->hasTargetWeight)
    +							value*=weapon->TargetWeight(*ui);
     						targets.insert(pair<float,CUnit*>(value,*ui));
     					}
     				}
    Index: Sim/Units/COB/CobFile.cpp
    ===================================================================
    --- Sim/Units/COB/CobFile.cpp	(revision 4750)
    +++ Sim/Units/COB/CobFile.cpp	(working copy)
    @@ -166,7 +166,7 @@
     	}
     
     	//Map common function names to indicies
    -	scriptIndex.resize(COBFN_Last + COB_MaxWeapons * 7);
    +	scriptIndex.resize(COBFN_Last + COB_MaxWeapons * 8);
     	scriptIndex[COBFN_Create] = getFunctionId("Create");
     	scriptIndex[COBFN_StartMoving] = getFunctionId("StartMoving");
     	scriptIndex[COBFN_StopMoving] = getFunctionId("StopMoving");
    @@ -199,6 +199,7 @@
     		scriptIndex[COBFN_EndBurst + i] = getFunctionId("EndBurst" + weap);
     		scriptIndex[COBFN_Shot + i] = getFunctionId("Shot" + weap);
     		scriptIndex[COBFN_BlockShot + i] = getFunctionId("BlockShot" + weap);
    +		scriptIndex[COBFN_TargetWeight + i] = getFunctionId("TargetWeight" + weap);
     
     		// If new-naming functions are not found, we need to support the old naming scheme
     		if (i > 2)
    Index: Sim/Units/COB/CobFile.h
    ===================================================================
    --- Sim/Units/COB/CobFile.h	(revision 4750)
    +++ Sim/Units/COB/CobFile.h	(working copy)
    @@ -48,6 +48,7 @@
     const int COBFN_EndBurst = COBFN_FirePrimary + COB_MaxWeapons;
     const int COBFN_Shot = COBFN_EndBurst + COB_MaxWeapons;
     const int COBFN_BlockShot = COBFN_Shot + COB_MaxWeapons;
    +const int COBFN_TargetWeight = COBFN_BlockShot + COB_MaxWeapons;
     
     class CCobFile
     {
    Index: Sim/Units/COB/CobInstance.cpp
    ===================================================================
    --- Sim/Units/COB/CobInstance.cpp	(revision 4750)
    +++ Sim/Units/COB/CobInstance.cpp	(working copy)
    @@ -101,6 +101,7 @@
     #define SHIELD_POWER             95 // set or get
     #define STEALTH                  96 // set or get
     #define CRASHING                 97 // set or get, returns whether aircraft isCrashing state
    +#define CHANGE_TARGET            98 // set, the value it's set to determines the affected weapon
     #define COB_ID                  100 // get
     #define ALPHA_THRESHOLD         103 // set or get
     
    @@ -1399,6 +1400,10 @@
     			}
     			break;
     		}
    +		case CHANGE_TARGET: {
    +			unit->weapons[param - 1]->avoidTarget = true;
    +			break;
    +		}
     		case ALPHA_THRESHOLD: {
     			unit->alphaThreshold = float(param) / 255.0f;
     			break;
    Index: Sim/Weapons/Weapon.cpp
    ===================================================================
    --- Sim/Weapons/Weapon.cpp	(revision 4750)
    +++ Sim/Weapons/Weapon.cpp	(working copy)
    @@ -52,7 +52,9 @@
     	CR_MEMBER(fireSoundId),
     	CR_MEMBER(fireSoundVolume),
     	CR_MEMBER(cobHasBlockShot),
    +	CR_MEMBER(hasTargetWeight),
     	CR_MEMBER(angleGood),
    +	CR_MEMBER(avoidTarget),
     	CR_MEMBER(maxAngleDif),
     	CR_MEMBER(wantedDir),
     	CR_MEMBER(lastRequestedDir),
    @@ -131,7 +133,9 @@
     	fireSoundId(0),
     	fireSoundVolume(0),
     	cobHasBlockShot(false),
    +	hasTargetWeight(false),
     	angleGood(false),
    +	avoidTarget(false),
     	maxAngleDif(0),
     	wantedDir(0,1,0),
     	lastRequestedDir(0,-1,0),
    @@ -188,6 +192,7 @@
     	weaponNum = num;
     
     	cobHasBlockShot = owner->cob->FunctionExist(COBFN_BlockShot + weaponNum);
    +	hasTargetWeight = owner->cob->FunctionExist(COBFN_TargetWeight + weaponNum);
     }
     
     
    @@ -212,6 +217,22 @@
     }
     
     
    +float CWeapon::TargetWeight(const CUnit* targetUnit) const
    +{
    +	const int unitID = targetUnit ? targetUnit->id : 0;
    +
    +	std::vector<int> args;
    +
    +	args.push_back(unitID);
    +	args.push_back(COBSCALE); // arg[1], for the return value
    +	                          // the default is 1.0
    +
    +	owner->cob->Call(COBFN_TargetWeight + weaponNum, args);
    +
    +	return (float)args[1] / (float)COBSCALE;
    +}
    +
    +
     void CWeapon::Update()
     {
     	if(hasCloseTarget){
    @@ -500,6 +521,7 @@
     	targetUnit=unit;
     	targetPos=tempTargetPos;
     	AddDeathDependence(targetUnit);
    +	avoidTarget=false;
     	return true;
     }
     
    @@ -528,6 +550,8 @@
     	if (haveUserTarget)          { return false; }
     
     	if (targetType == Target_None) { return true; }
    +	
    +	if (avoidTarget)             { return true; }
     
     	if (targetType == Target_Unit) {
     		if (targetUnit->category & badTargetCategory) {
    Index: Sim/Weapons/Weapon.h
    ===================================================================
    --- Sim/Weapons/Weapon.h	(revision 4750)
    +++ Sim/Weapons/Weapon.h	(working copy)
    @@ -38,6 +38,7 @@
     	bool TryTargetRotate(float3 pos, bool userTarget);
     	bool TryTargetHeading(short heading, float3 pos, bool userTarget, CUnit* unit = 0);
     	bool CobBlockShot(const CUnit* unit);
    +	float TargetWeight(const CUnit* unit) const;
     	void SlowUpdate(bool noAutoTargetOverride);
     	virtual void SlowUpdate();
     	virtual void Update();
    @@ -106,7 +107,9 @@
     	float fireSoundVolume;
     
     	bool cobHasBlockShot;							//set when the script has a BlockShot() function for this weapon
    +	bool hasTargetWeight;                            //set when there's a TargetWeight() function for this weapon
     	bool angleGood;										//set when script indicated ready to fire
    +	bool avoidTarget;								//set when the script wants the weapon to pick a new target, reset once one has been chosen
     	bool subClassReady;								//set to false if the subclassed weapon cant fire for some reason
     	bool onlyForward;									//can only fire in the forward direction of the unit (for aircrafts mostly?)
     
    
    patch file icon changeTarget.patch (5,620 bytes) 2007-11-10 22:09 +
  • patch file icon changeTarget1.patch (6,036 bytes) 2007-11-11 08:38 -
    Index: Game/GameHelper.cpp
    ===================================================================
    --- Game/GameHelper.cpp	(revision 4750)
    +++ Game/GameHelper.cpp	(working copy)
    @@ -433,13 +433,15 @@
     							*(0.01f+(*ui)->crashing)
     							/(weapon->weaponDef->damages[(*ui)->armorType]*(*ui)->curArmorMultiple*(*ui)->power*(0.7f+gs->randFloat()*0.6f));
     						if((*ui)==lastTarget)
    -							value*=0.4f;
    +							value*=weapon->avoidTarget ? 10.0f : 0.4f;
     						if((*ui)->category & weapon->badTargetCategory)
     							value*=100;
     						if(paralyzer && (*ui)->health-(*ui)->paralyzeDamage<(*ui)->maxHealth*0.09f)
     							value*=4;
     						if((*ui)->crashing)
     							value*=10;
    +						if(weapon->hasTargetWeight)
    +							value*=weapon->TargetWeight(*ui);
     						targets.insert(pair<float,CUnit*>(value,*ui));
     					}
     				}
    Index: Sim/Units/COB/CobFile.cpp
    ===================================================================
    --- Sim/Units/COB/CobFile.cpp	(revision 4750)
    +++ Sim/Units/COB/CobFile.cpp	(working copy)
    @@ -166,7 +166,7 @@
     	}
     
     	//Map common function names to indicies
    -	scriptIndex.resize(COBFN_Last + COB_MaxWeapons * 7);
    +	scriptIndex.resize(COBFN_Last + COB_MaxWeapons * 8);
     	scriptIndex[COBFN_Create] = getFunctionId("Create");
     	scriptIndex[COBFN_StartMoving] = getFunctionId("StartMoving");
     	scriptIndex[COBFN_StopMoving] = getFunctionId("StopMoving");
    @@ -199,6 +199,7 @@
     		scriptIndex[COBFN_EndBurst + i] = getFunctionId("EndBurst" + weap);
     		scriptIndex[COBFN_Shot + i] = getFunctionId("Shot" + weap);
     		scriptIndex[COBFN_BlockShot + i] = getFunctionId("BlockShot" + weap);
    +		scriptIndex[COBFN_TargetWeight + i] = getFunctionId("TargetWeight" + weap);
     
     		// If new-naming functions are not found, we need to support the old naming scheme
     		if (i > 2)
    Index: Sim/Units/COB/CobFile.h
    ===================================================================
    --- Sim/Units/COB/CobFile.h	(revision 4750)
    +++ Sim/Units/COB/CobFile.h	(working copy)
    @@ -48,6 +48,7 @@
     const int COBFN_EndBurst = COBFN_FirePrimary + COB_MaxWeapons;
     const int COBFN_Shot = COBFN_EndBurst + COB_MaxWeapons;
     const int COBFN_BlockShot = COBFN_Shot + COB_MaxWeapons;
    +const int COBFN_TargetWeight = COBFN_BlockShot + COB_MaxWeapons;
     
     class CCobFile
     {
    Index: Sim/Units/COB/CobInstance.cpp
    ===================================================================
    --- Sim/Units/COB/CobInstance.cpp	(revision 4750)
    +++ Sim/Units/COB/CobInstance.cpp	(working copy)
    @@ -101,6 +101,7 @@
     #define SHIELD_POWER             95 // set or get
     #define STEALTH                  96 // set or get
     #define CRASHING                 97 // set or get, returns whether aircraft isCrashing state
    +#define CHANGE_TARGET            98 // set, the value it's set to determines the affected weapon
     #define COB_ID                  100 // get
     #define ALPHA_THRESHOLD         103 // set or get
     
    @@ -1399,6 +1400,10 @@
     			}
     			break;
     		}
    +		case CHANGE_TARGET: {
    +			unit->weapons[param - 1]->avoidTarget = true;
    +			break;
    +		}
     		case ALPHA_THRESHOLD: {
     			unit->alphaThreshold = float(param) / 255.0f;
     			break;
    Index: Sim/Weapons/Weapon.cpp
    ===================================================================
    --- Sim/Weapons/Weapon.cpp	(revision 4750)
    +++ Sim/Weapons/Weapon.cpp	(working copy)
    @@ -52,7 +52,9 @@
     	CR_MEMBER(fireSoundId),
     	CR_MEMBER(fireSoundVolume),
     	CR_MEMBER(cobHasBlockShot),
    +	CR_MEMBER(hasTargetWeight),
     	CR_MEMBER(angleGood),
    +	CR_MEMBER(avoidTarget),
     	CR_MEMBER(maxAngleDif),
     	CR_MEMBER(wantedDir),
     	CR_MEMBER(lastRequestedDir),
    @@ -131,7 +133,9 @@
     	fireSoundId(0),
     	fireSoundVolume(0),
     	cobHasBlockShot(false),
    +	hasTargetWeight(false),
     	angleGood(false),
    +	avoidTarget(false),
     	maxAngleDif(0),
     	wantedDir(0,1,0),
     	lastRequestedDir(0,-1,0),
    @@ -188,6 +192,7 @@
     	weaponNum = num;
     
     	cobHasBlockShot = owner->cob->FunctionExist(COBFN_BlockShot + weaponNum);
    +	hasTargetWeight = owner->cob->FunctionExist(COBFN_TargetWeight + weaponNum);
     }
     
     
    @@ -212,6 +217,22 @@
     }
     
     
    +float CWeapon::TargetWeight(const CUnit* targetUnit) const
    +{
    +	const int unitID = targetUnit ? targetUnit->id : 0;
    +
    +	std::vector<int> args;
    +
    +	args.push_back(unitID);
    +	args.push_back(COBSCALE); // arg[1], for the return value
    +	                          // the default is 1.0
    +
    +	owner->cob->Call(COBFN_TargetWeight + weaponNum, args);
    +
    +	return (float)args[1] / (float)COBSCALE;
    +}
    +
    +
     void CWeapon::Update()
     {
     	if(hasCloseTarget){
    @@ -500,6 +521,7 @@
     	targetUnit=unit;
     	targetPos=tempTargetPos;
     	AddDeathDependence(targetUnit);
    +	avoidTarget=false;
     	return true;
     }
     
    @@ -528,6 +550,8 @@
     	if (haveUserTarget)          { return false; }
     
     	if (targetType == Target_None) { return true; }
    +	
    +	if (avoidTarget)             { return true; }
     
     	if (targetType == Target_Unit) {
     		if (targetUnit->category & badTargetCategory) {
    Index: Sim/Weapons/Weapon.h
    ===================================================================
    --- Sim/Weapons/Weapon.h	(revision 4750)
    +++ Sim/Weapons/Weapon.h	(working copy)
    @@ -38,6 +38,7 @@
     	bool TryTargetRotate(float3 pos, bool userTarget);
     	bool TryTargetHeading(short heading, float3 pos, bool userTarget, CUnit* unit = 0);
     	bool CobBlockShot(const CUnit* unit);
    +	float TargetWeight(const CUnit* unit) const;
     	void SlowUpdate(bool noAutoTargetOverride);
     	virtual void SlowUpdate();
     	virtual void Update();
    @@ -106,7 +107,9 @@
     	float fireSoundVolume;
     
     	bool cobHasBlockShot;							//set when the script has a BlockShot() function for this weapon
    +	bool hasTargetWeight;                            //set when there's a TargetWeight() function for this weapon
     	bool angleGood;										//set when script indicated ready to fire
    +	bool avoidTarget;								//set when the script wants the weapon to pick a new target, reset once one has been chosen
     	bool subClassReady;								//set to false if the subclassed weapon cant fire for some reason
     	bool onlyForward;									//can only fire in the forward direction of the unit (for aircrafts mostly?)
     
    
    patch file icon changeTarget1.patch (6,036 bytes) 2007-11-11 08:38 +
  • patch file icon changeTarget_updated.patch (5,884 bytes) 2007-11-14 17:24 -
    Index: Game/GameHelper.cpp
    ===================================================================
    --- Game/GameHelper.cpp	(revision 4786)
    +++ Game/GameHelper.cpp	(working copy)
    @@ -433,13 +433,15 @@
     							*(0.01f+(*ui)->crashing)
     							/(weapon->weaponDef->damages[(*ui)->armorType]*(*ui)->curArmorMultiple*(*ui)->power*(0.7f+gs->randFloat()*0.6f));
     						if((*ui)==lastTarget)
    -							value*=0.4f;
    +							value*=weapon->avoidTarget ? 10.0f : 0.4f;
     						if((*ui)->category & weapon->badTargetCategory)
     							value*=100;
     						if(paralyzer && (*ui)->health-(*ui)->paralyzeDamage<(*ui)->maxHealth*0.09f)
     							value*=4;
     						if((*ui)->crashing)
     							value*=10;
    +						if(weapon->hasTargetWeight)
    +							value*=weapon->TargetWeight(*ui);
     						targets.insert(pair<float,CUnit*>(value,*ui));
     					}
     				}
    Index: Sim/Units/COB/CobFile.cpp
    ===================================================================
    --- Sim/Units/COB/CobFile.cpp	(revision 4786)
    +++ Sim/Units/COB/CobFile.cpp	(working copy)
    @@ -199,6 +199,7 @@
     		scriptIndex[COBFN_EndBurst       + i] = getFunctionId("EndBurst"  + weap);
     		scriptIndex[COBFN_Shot           + i] = getFunctionId("Shot"      + weap);
     		scriptIndex[COBFN_BlockShot      + i] = getFunctionId("BlockShot" + weap);
    +		scriptIndex[COBFN_TargetWeight + i] = getFunctionId("TargetWeight" + weap);
     
     		// If new-naming functions are not found, we need to support the old naming scheme
     		if (i > 2) {
    Index: Sim/Units/COB/CobFile.h
    ===================================================================
    --- Sim/Units/COB/CobFile.h	(revision 4786)
    +++ Sim/Units/COB/CobFile.h	(working copy)
    @@ -48,7 +48,8 @@
     const int COBFN_EndBurst       = COBFN_FirePrimary    + COB_MaxWeapons;
     const int COBFN_Shot           = COBFN_EndBurst       + COB_MaxWeapons;
     const int COBFN_BlockShot      = COBFN_Shot           + COB_MaxWeapons;
    -const int COBFN_Weapon_Funcs   = 7;
    +const int COBFN_TargetWeight   = COBFN_BlockShot      + COB_MaxWeapons;
    +const int COBFN_Weapon_Funcs   = 8;
     
     class CCobFile
     {
    Index: Sim/Units/COB/CobInstance.cpp
    ===================================================================
    --- Sim/Units/COB/CobInstance.cpp	(revision 4786)
    +++ Sim/Units/COB/CobInstance.cpp	(working copy)
    @@ -101,6 +101,7 @@
     #define SHIELD_POWER              95 // set or get
     #define STEALTH                   96 // set or get
     #define CRASHING                  97 // set or get, returns whether aircraft isCrashing state
    +#define CHANGE_TARGET             98 // set, the value it's set to determines the affected weapon
     #define COB_ID                   100 // get
     #define ALPHA_THRESHOLD          103 // set or get
     #define SET_WEAPON_UNIT_TARGET   106 // get (fake set)
    @@ -1431,6 +1432,10 @@
     			}
     			break;
     		}
    +		case CHANGE_TARGET: {
    +			unit->weapons[param - 1]->avoidTarget = true;
    +			break;
    +		}
     		case ALPHA_THRESHOLD: {
     			unit->alphaThreshold = float(param) / 255.0f;
     			break;
    Index: Sim/Weapons/Weapon.cpp
    ===================================================================
    --- Sim/Weapons/Weapon.cpp	(revision 4786)
    +++ Sim/Weapons/Weapon.cpp	(working copy)
    @@ -52,7 +52,9 @@
     	CR_MEMBER(fireSoundId),
     	CR_MEMBER(fireSoundVolume),
     	CR_MEMBER(cobHasBlockShot),
    +	CR_MEMBER(hasTargetWeight),
     	CR_MEMBER(angleGood),
    +	CR_MEMBER(avoidTarget),
     	CR_MEMBER(maxAngleDif),
     	CR_MEMBER(wantedDir),
     	CR_MEMBER(lastRequestedDir),
    @@ -131,7 +133,9 @@
     	fireSoundId(0),
     	fireSoundVolume(0),
     	cobHasBlockShot(false),
    +	hasTargetWeight(false),
     	angleGood(false),
    +	avoidTarget(false),
     	maxAngleDif(0),
     	wantedDir(0,1,0),
     	lastRequestedDir(0,-1,0),
    @@ -188,6 +192,7 @@
     	weaponNum = num;
     
     	cobHasBlockShot = owner->cob->FunctionExist(COBFN_BlockShot + weaponNum);
    +	hasTargetWeight = owner->cob->FunctionExist(COBFN_TargetWeight + weaponNum);
     }
     
     
    @@ -212,6 +217,22 @@
     }
     
     
    +float CWeapon::TargetWeight(const CUnit* targetUnit) const
    +{
    +	const int unitID = targetUnit ? targetUnit->id : 0;
    +
    +	std::vector<int> args;
    +
    +	args.push_back(unitID);
    +	args.push_back(COBSCALE); // arg[1], for the return value
    +	                          // the default is 1.0
    +
    +	owner->cob->Call(COBFN_TargetWeight + weaponNum, args);
    +
    +	return (float)args[1] / (float)COBSCALE;
    +}
    +
    +
     void CWeapon::Update()
     {
     	if(hasCloseTarget){
    @@ -500,6 +521,7 @@
     	targetUnit=unit;
     	targetPos=tempTargetPos;
     	AddDeathDependence(targetUnit);
    +	avoidTarget=false;
     	return true;
     }
     
    @@ -528,6 +550,8 @@
     	if (haveUserTarget)          { return false; }
     
     	if (targetType == Target_None) { return true; }
    +	
    +	if (avoidTarget)             { return true; }
     
     	if (targetType == Target_Unit) {
     		if (targetUnit->category & badTargetCategory) {
    Index: Sim/Weapons/Weapon.h
    ===================================================================
    --- Sim/Weapons/Weapon.h	(revision 4786)
    +++ Sim/Weapons/Weapon.h	(working copy)
    @@ -38,6 +38,7 @@
     	bool TryTargetRotate(float3 pos, bool userTarget);
     	bool TryTargetHeading(short heading, float3 pos, bool userTarget, CUnit* unit = 0);
     	bool CobBlockShot(const CUnit* unit);
    +	float TargetWeight(const CUnit* unit) const;
     	void SlowUpdate(bool noAutoTargetOverride);
     	virtual void SlowUpdate();
     	virtual void Update();
    @@ -106,7 +107,9 @@
     	float fireSoundVolume;
     
     	bool cobHasBlockShot;							//set when the script has a BlockShot() function for this weapon
    +	bool hasTargetWeight;                            //set when there's a TargetWeight() function for this weapon
     	bool angleGood;										//set when script indicated ready to fire
    +	bool avoidTarget;								//set when the script wants the weapon to pick a new target, reset once one has been chosen
     	bool subClassReady;								//set to false if the subclassed weapon cant fire for some reason
     	bool onlyForward;									//can only fire in the forward direction of the unit (for aircrafts mostly?)
     
    
    patch file icon changeTarget_updated.patch (5,884 bytes) 2007-11-14 17:24 +

-Relationships
+Relationships

-Notes

~0001408

imbaczek (reporter)

IMO this should be a separate function, say BlockTargetChoice or something similar. BlockShot is too suggestive and should do just what its name implies. Anything more will be confusing.

Other than that I like the idea. A more complete patch also should provide a Lua call-in (perhaps also a call-out to register receivers of a call-in for performance reasons) so modders won't have to change BOS of every unit they want this behaviour on - but that's more of a suggestion.

~0001409

KDR_11k (reporter)

BlockTarget would also have to be able to block shots since there are loads of cases where the same condition should cause a blocked shot and a changed target. I thought of it more in that context, i.e. "stop shooting and look for something else".

~0001410

imbaczek (reporter)

Maybe BlockTarget should be called before any BlockShotX and somehow change/discard the attack command that the unit is executing?

~0001411

KDR_11k (reporter)

Okay, I restarted the idea from scratch.

Now it introduces the COB call-in TargetWeight(targetID, weight), weight defaults to 65536 which represents 1.0 and is multiplied with the target's value to determine priorities.

It also adds the set constant CHANGE_TARGET:
set CHANGE_TARGET to x makes weaponX pick a new target.

~0001412

KDR_11k (reporter)

Added a minor change that gives less priority (instead of the default, more) to the last target when set CHANGE_TARGET was used, this improves the behaviour for weapons without TargetWeight.

~0001417

imbaczek (reporter)

I quite like the idea, does what it says it does.

I'll check this out Tuesday or so.

~0001422

imbaczek (reporter)

unfortunately it seems that the patch has suffered from bitrot already. please resubmit?

~0001424

KDR_11k (reporter)

Must have been corrupted on your end, tombom reports he can use it just fine and Diff says it's identical to the file I uploaded. Or do you mean I should take it against a newer revision or something?

~0001425

imbaczek (reporter)

yes, I mean it conflicts in newer revisions (apparently trepan changed some COB stuff in r4781.)

~0001427

KDR_11k (reporter)

Okay, fixed it. Trepan changed some whitespaces in the area.

~0001428

imbaczek (reporter)

applied and compiled cleanly. testing now.

~0001431

imbaczek (reporter)

committed this.

I can't seem to get repeatable behavior with TargetWeightX (I didn't try to dig deep into target selection code though.) Gave it the benefit of doubt; it doesn't break existing functionality.

r4788.
+Notes

-Issue History
Date Modified Username Field Change
2007-11-10 18:33 KDR_11k New Issue
2007-11-10 18:33 KDR_11k File Added: blockTarget.patch
2007-11-10 19:15 imbaczek Note Added: 0001408
2007-11-10 20:12 KDR_11k Note Added: 0001409
2007-11-10 21:49 imbaczek Note Added: 0001410
2007-11-10 22:09 KDR_11k File Added: changeTarget.patch
2007-11-10 22:19 KDR_11k Note Added: 0001411
2007-11-11 08:38 KDR_11k File Added: changeTarget1.patch
2007-11-11 08:40 KDR_11k Note Added: 0001412
2007-11-12 01:02 imbaczek Note Added: 0001417
2007-11-14 16:02 imbaczek Note Added: 0001422
2007-11-14 16:34 KDR_11k Note Added: 0001424
2007-11-14 17:06 imbaczek Note Added: 0001425
2007-11-14 17:24 KDR_11k File Added: changeTarget_updated.patch
2007-11-14 17:25 KDR_11k Note Added: 0001427
2007-11-14 19:27 imbaczek Note Added: 0001428
2007-11-14 20:54 imbaczek Status new => resolved
2007-11-14 20:54 imbaczek Resolution open => fixed
2007-11-14 20:54 imbaczek Assigned To => imbaczek
2007-11-14 20:55 imbaczek Note Added: 0001431
+Issue History