Attached Files |
-
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();
-
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?)
-
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?)
-
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?)
|
---|