2025-08-14 01:06 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000979Spring engineGeneralpublic2008-10-04 23:59
Reporterdet 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusclosedResolutionfixed 
Product Version0.76b1+svn 
Target VersionFixed in Version0.76b1+svn 
Summary0000979: [PATCH] New modrules tags to let {repair,reclaim,capture} cost energy
DescriptionThis patch adds the following new tags to modrules.{lua,tdf}

repair.energyCostFactor: Used to determine the energy cost used to repair a unit. Defaults to 0.0, which is backwards compatible behavior.

capture.energyCostFactor: Used to determine the energy cost used to capture a unit. Defaults to 0.0, which is backwards compatible behavior.

reclaim.unitEnergyCostFactor: Used to determine the energy cost used to reclaim a live or under construction unit. Defaults to 0.0, which is backwards compatible behaviour.

reclaim.featureEnergyCostFactor: Used to determine the energy cost used to reclaim a feature. Defaults to 0.0, which is backwards compatible behavior.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon energy_costs.patch (8,575 bytes) 2008-07-13 15:26 -
    Index: rts/Sim/ModInfo.h
    ===================================================================
    --- rts/Sim/ModInfo.h	(revision 6162)
    +++ rts/Sim/ModInfo.h	(working copy)
    @@ -25,10 +25,18 @@
     	int constructionDecayTime;  //How long until they start decaying?
     	float constructionDecaySpeed; //How fast do they decay?
     
    -	// Reclaim behaviour
    -	int multiReclaim;	// 0 = 1 reclaimer per feature max, otherwise unlimited
    -	int reclaimMethod;	// 0 = gradual reclaim, 1 = all reclaimed at end, otherwise reclaim in reclaimMethod chunks
    +	//Reclaim behaviour
    +	int multiReclaim;	              // 0 = 1 reclaimer per feature max, otherwise unlimited
    +	int reclaimMethod;	              // 0 = gradual reclaim, 1 = all reclaimed at end, otherwise reclaim in reclaimMethod chunks
    +	float reclaimUnitEnergyCostFactor;    // How much should energy should reclaiming a unit cost, default 0.0
    +	float reclaimFeatureEnergyCostFactor; // How much should energy should reclaiming a feature cost, default 0.0
     
    +	//Repair beheaviour
    +	float repairEnergyCostFactor; // How much should energy should repair cost, default 0.0
    +
    +	//Capture beheaviour
    +	float captureEnergyCostFactor; // How much should energy should capture cost, default 0.0
    +
     	//Transportation behaviour
     	int transportGround;	//0 = all ground units cannot be transported, 1 = all ground units can be transported (mass and size restrictions still apply). Defaults to 1.
     	int transportHover;	//0 = all hover units cannot be transported, 1 = all hover units can be transported (mass and size restrictions still apply). Defaults to 0.
    Index: rts/Sim/Units/Unit.cpp
    ===================================================================
    --- rts/Sim/Units/Unit.cpp	(revision 6162)
    +++ rts/Sim/Units/Unit.cpp	(working copy)
    @@ -1649,17 +1649,19 @@
     
     bool CUnit::AddBuildPower(float amount, CUnit* builder)
     {
    +	const float part = amount / buildTime;
    +	const float metalUse  = (metalCost  * part);
    +	const float energyUse = (energyCost * part);
    +
     	if (amount >= 0.0f) { //  build / repair
     		if (!beingBuilt && (health >= maxHealth)) {
     			return false;
     		}
     
     		lastNanoAdd = gs->frameNum;
    -		const float part = amount / buildTime;
     
    -		if (beingBuilt) {
    -			const float metalUse  = (metalCost  * part);
    -			const float energyUse = (energyCost * part);
    +
    +		if (beingBuilt) { //build
     			if ((gs->Team(builder->team)->metal  >= metalUse) &&
     			    (gs->Team(builder->team)->energy >= energyUse) &&
     			    (!luaRules || luaRules->AllowUnitBuildStep(builder, this, part))) {
    @@ -1686,7 +1688,14 @@
     			}
     			return false;
     		}
    -		else {
    +		else { //repair
    +			const float energyUseScaled = energyUse * modInfo.repairEnergyCostFactor;
    +
    +	  		if (!builder->UseEnergy(energyUseScaled)) {
    +				gs->Team(builder->team)->energyPull += energyUseScaled;
    +				return false;
    +			}
    +
     			if (health < maxHealth) {
     				repairAmount += amount;
     				health += maxHealth * part;
    @@ -1702,14 +1711,22 @@
     		if (isDead) {
     			return false;
     		}
    -		const float part = amount / buildTime;
    +
     		if (luaRules && !luaRules->AllowUnitBuildStep(builder, this, part)) {
     			return false;
     		}
    +
     		restTime = 0;
    +		const float energyUseScaled = energyUse * modInfo.reclaimUnitEnergyCostFactor;
    +	  
    +		if (!builder->UseEnergy(-energyUseScaled)) {
    +			gs->Team(builder->team)->energyPull += energyUseScaled;
    +			return false;
    +		}
    +
     		health += maxHealth * part;
     		if (beingBuilt) {
    -			builder->AddMetal(metalCost*-part);
    +			builder->AddMetal(-metalUse);
     			buildProgress+=part;
     			if(buildProgress<0 || health<0){
     				KillUnit(false, true, NULL);
    Index: rts/Sim/Units/UnitTypes/Builder.cpp
    ===================================================================
    --- rts/Sim/Units/UnitTypes/Builder.cpp	(revision 6162)
    +++ rts/Sim/Units/UnitTypes/Builder.cpp	(working copy)
    @@ -314,25 +314,38 @@
     	}
     	else if(curCapture && f3Dist(curCapture->pos, pos)<buildDistance+curCapture->radius && inBuildStance){
     		if(curCapture->team!=team){
    -			curCapture->captureProgress+=1.0f/(150+curCapture->buildTime/captureSpeed*(curCapture->health+curCapture->maxHealth)/curCapture->maxHealth*0.4f);
    -			CreateNanoParticle(curCapture->midPos,curCapture->radius*0.7f,false);
    -			if(curCapture->captureProgress > 1.0f){
    -				if (!curCapture->ChangeTeam(team, CUnit::ChangeCaptured)) {
    -					// capture failed
    -					ENTER_MIXED;
    -					if (team == gu->myTeam) {
    -						logOutput.Print("%s: Capture failed, unit type limit reached", unitDef->humanName.c_str());
    -						logOutput.SetLastMsgPos(pos);
    +
    +			float captureProgressTemp = curCapture->captureProgress + 1.0f/(150+curCapture->buildTime/captureSpeed*(curCapture->health+curCapture->maxHealth)/curCapture->maxHealth*0.4f);
    +			if (captureProgressTemp >= 1.0f) {
    +				captureProgressTemp = 1.0f;
    +			}
    +	
    +			const float captureFraction = captureProgressTemp - curCapture->captureProgress;
    +			const float energyUseScaled = curCapture->energyCost * captureFraction * modInfo.captureEnergyCostFactor;
    +
    +			if (!UseEnergy(energyUseScaled)) {
    +				gs->Team(team)->energyPull += energyUseScaled;
    +			} else {
    +				curCapture->captureProgress = captureProgressTemp;
    +				CreateNanoParticle(curCapture->midPos,curCapture->radius*0.7f,false);
    +				if(curCapture->captureProgress > 1.0f){
    +					if (!curCapture->ChangeTeam(team, CUnit::ChangeCaptured)) {
    +						// capture failed
    +						ENTER_MIXED;
    +						if (team == gu->myTeam) {
    +							logOutput.Print("%s: Capture failed, unit type limit reached", unitDef->humanName.c_str());
    +							logOutput.SetLastMsgPos(pos);
    +						}
    +						ENTER_SYNCED;
    +					} else {
    +						// capture succesful
    +						int oldLineage = curCapture->lineage;
    +						curCapture->lineage = this->lineage;
    +						gs->Team(oldLineage)->LeftLineage(curCapture);
     					}
    -					ENTER_SYNCED;
    -				} else {
    -					// capture succesful
    -					int oldLineage = curCapture->lineage;
    -					curCapture->lineage = this->lineage;
    -					gs->Team(oldLineage)->LeftLineage(curCapture);
    +					curCapture->captureProgress=0.0f;
    +					StopBuild(true);
     				}
    -				curCapture->captureProgress=0.0f;
    -				StopBuild(true);
     			}
     		} else {
     			StopBuild(true);
    Index: rts/Sim/ModInfo.cpp
    ===================================================================
    --- rts/Sim/ModInfo.cpp	(revision 6162)
    +++ rts/Sim/ModInfo.cpp	(working copy)
    @@ -60,7 +60,17 @@
     	const LuaTable reclaimTbl = root.SubTable("reclaim");
     	multiReclaim  = reclaimTbl.GetInt("multiReclaim",  0);
     	reclaimMethod = reclaimTbl.GetInt("reclaimMethod", 1);
    +	reclaimUnitEnergyCostFactor = reclaimTbl.GetFloat("unitEnergyCostFactor", 0.0);
    +	reclaimFeatureEnergyCostFactor = reclaimTbl.GetFloat("featureEnergyCostFactor", 0.0);
     
    +	// repair
    +	const LuaTable repairTbl = root.SubTable("repair");
    +	repairEnergyCostFactor = repairTbl.GetFloat("energyCostFactor", 0.0);
    +
    +	// capture
    +	const LuaTable captureTbl = root.SubTable("capture");
    +	captureEnergyCostFactor = captureTbl.GetFloat("energyCostFactor", 0.0);
    +
     	// fire-at-dead-units
     	const LuaTable fireAtDeadTbl = root.SubTable("fireAtDead");
     	fireAtKilled   = fireAtDeadTbl.GetBool("fireAtKilled", false);
    Index: rts/Sim/Features/Feature.cpp
    ===================================================================
    --- rts/Sim/Features/Feature.cpp	(revision 6162)
    +++ rts/Sim/Features/Feature.cpp	(working copy)
    @@ -306,15 +306,24 @@
     			return false;
     		}
     
    -		reclaimLeft -= part;
    -
    +		float reclaimLeftTemp = reclaimLeft - part;
     		// stop the last bit giving too much resource
    -		if (reclaimLeft < 0) {
    -			reclaimLeft = 0;
    +		if (reclaimLeftTemp < 0) {
    +			reclaimLeftTemp = 0;
     		}
     
    -		const float fractionReclaimed = oldReclaimLeft - reclaimLeft;
    +		const float fractionReclaimed = oldReclaimLeft - reclaimLeftTemp;
    +		const float metalFraction = def->metal * fractionReclaimed;
    +		const float energyFraction = def->energy * fractionReclaimed;
    +		const float energyUseScaled = metalFraction * modInfo.reclaimFeatureEnergyCostFactor;
     
    +		if (!builder->UseEnergy(energyUseScaled)) {
    +			gs->Team(builder->team)->energyPull += energyUseScaled;
    +			return false;
    +		}
    +
    +		reclaimLeft = reclaimLeftTemp;
    +
     		if ((modInfo.reclaimMethod == 1) && (reclaimLeft == 0)) {
     			// All-at-end method
     			builder->AddMetal(def->metal);
    @@ -322,8 +331,8 @@
     		}
     		else if (modInfo.reclaimMethod == 0) {
     			// Gradual reclaim
    -			builder->AddMetal(def->metal * fractionReclaimed);
    -			builder->AddEnergy(def->energy * fractionReclaimed);
    +			builder->AddMetal(metalFraction);
    +			builder->AddEnergy(energyFraction);
     		}
     		else {
     			// Chunky reclaiming, work out how many chunk boundaries we crossed
    
    patch file icon energy_costs.patch (8,575 bytes) 2008-07-13 15:26 +
  • diff file icon energy_costs2.diff (13,165 bytes) 2008-07-16 08:33 -
    Index: rts/Sim/ModInfo.h
    ===================================================================
    --- rts/Sim/ModInfo.h	(revision 6162)
    +++ rts/Sim/ModInfo.h	(working copy)
    @@ -25,10 +25,25 @@
     	int constructionDecayTime;  //How long until they start decaying?
     	float constructionDecaySpeed; //How fast do they decay?
     
    -	// Reclaim behaviour
    -	int multiReclaim;	// 0 = 1 reclaimer per feature max, otherwise unlimited
    -	int reclaimMethod;	// 0 = gradual reclaim, 1 = all reclaimed at end, otherwise reclaim in reclaimMethod chunks
    +	//Reclaim behaviour
    +	int multiReclaim;	              // 0 = 1 reclaimer per feature max, otherwise unlimited
    +	int reclaimMethod;	              // 0 = gradual reclaim, 1 = all reclaimed at end, otherwise reclaim in reclaimMethod chunks
    +	int reclaimUnitMethod;                // 0 = Revert to wireframe, gradual reclaim, 1 = Subtract HP, give full metal at end, default 1
    +	float reclaimUnitEnergyCostFactor;    // How much should energy should reclaiming a unit cost, default 0.0
    +	float reclaimUnitEfficiency;          // How much metal should reclaim return, default 1.0
    +	float reclaimFeatureEnergyCostFactor; // How much should energy should reclaiming a feature cost, default 0.0
    +	bool reclaimAllowEnemies;             // Allow reclaiming enemies? default true
    +	bool reclaimAllowAllies;              // Allow reclaiming allies? default true
     
    +	//Repair beheaviour
    +	float repairEnergyCostFactor; // How much should energy should repair cost, default 0.0
    +
    +	//Ressurect behaviour
    +	float resurrectEnergyCostFactor; // How much should energy should resurrect cost, default 0.5
    +
    +	//Capture beheaviour
    +	float captureEnergyCostFactor; // How much should energy should capture cost, default 0.0
    +
     	//Transportation behaviour
     	int transportGround;	//0 = all ground units cannot be transported, 1 = all ground units can be transported (mass and size restrictions still apply). Defaults to 1.
     	int transportHover;	//0 = all hover units cannot be transported, 1 = all hover units can be transported (mass and size restrictions still apply). Defaults to 0.
    Index: rts/Sim/Units/CommandAI/BuilderCAI.cpp
    ===================================================================
    --- rts/Sim/Units/CommandAI/BuilderCAI.cpp	(revision 6162)
    +++ rts/Sim/Units/CommandAI/BuilderCAI.cpp	(working copy)
    @@ -20,6 +20,7 @@
     #include "Sim/Features/FeatureHandler.h"
     #include "Sim/Misc/GroundBlockingObjectMap.h"
     #include "Sim/Misc/QuadField.h"
    +#include "Sim/ModInfo.h"
     #include "Sim/MoveTypes/MoveType.h"
     #include "Sim/Units/UnitSet.h"
     #include "Sim/Units/UnitDefHandler.h"
    @@ -724,7 +725,8 @@
     
     		} else {                   //reclaim unit
     			CUnit* unit=uh->units[id];
    -			if(unit && unit!=owner && unit->unitDef->reclaimable && UpdateTargetLostTimer(id)){
    +
    +			if(unit && unit!=owner && unit->unitDef->reclaimable && UpdateTargetLostTimer(id) && unit->AllowedReclaim(owner) ){
     				if(!ReclaimObject(unit)){
     					StopMove();
     					FinishCommand();
    Index: rts/Sim/Units/CommandAI/CommandAI.cpp
    ===================================================================
    --- rts/Sim/Units/CommandAI/CommandAI.cpp	(revision 6162)
    +++ rts/Sim/Units/CommandAI/CommandAI.cpp	(working copy)
    @@ -15,6 +15,7 @@
     #include "Map/Ground.h"
     #include "Sim/Features/Feature.h"
     #include "Sim/Features/FeatureHandler.h"
    +#include "Sim/ModInfo.h"
     #include "Sim/MoveTypes/MoveType.h"
     #include "Sim/Units/UnitDef.h"
     #include "Sim/Units/UnitDefHandler.h"
    @@ -401,6 +402,7 @@
     			CUnit* unit = uh->units[unitID];
     			if (unit && !unit->unitDef->reclaimable)
     				return false;
    +			if (unit && !unit->AllowedReclaim(owner)) return false;
     		} else {
     			const CFeatureSet& fset = featureHandler->GetActiveFeatures();
     			CFeatureSet::const_iterator f = fset.find(unitID - MAX_UNITS);
    Index: rts/Sim/Units/Unit.cpp
    ===================================================================
    --- rts/Sim/Units/Unit.cpp	(revision 6162)
    +++ rts/Sim/Units/Unit.cpp	(working copy)
    @@ -571,7 +571,6 @@
     	metalMakeI = metalUseI = energyMakeI = energyUseI = 0.0f;
     }
     
    -
     void CUnit::SetLosStatus(int at, unsigned short newStatus)
     {
     	const unsigned short currStatus = losStatus[at];
    @@ -1649,17 +1648,19 @@
     
     bool CUnit::AddBuildPower(float amount, CUnit* builder)
     {
    +	const float part = amount / buildTime;
    +	const float metalUse  = (metalCost  * part);
    +	const float energyUse = (energyCost * part);
    +
     	if (amount >= 0.0f) { //  build / repair
     		if (!beingBuilt && (health >= maxHealth)) {
     			return false;
     		}
     
     		lastNanoAdd = gs->frameNum;
    -		const float part = amount / buildTime;
     
    -		if (beingBuilt) {
    -			const float metalUse  = (metalCost  * part);
    -			const float energyUse = (energyCost * part);
    +
    +		if (beingBuilt) { //build
     			if ((gs->Team(builder->team)->metal  >= metalUse) &&
     			    (gs->Team(builder->team)->energy >= energyUse) &&
     			    (!luaRules || luaRules->AllowUnitBuildStep(builder, this, part))) {
    @@ -1686,7 +1687,14 @@
     			}
     			return false;
     		}
    -		else {
    +		else { //repair
    +			const float energyUseScaled = energyUse * modInfo.repairEnergyCostFactor;
    +
    +	  		if (!builder->UseEnergy(energyUseScaled)) {
    +				gs->Team(builder->team)->energyPull += energyUseScaled;
    +				return false;
    +			}
    +
     			if (health < maxHealth) {
     				repairAmount += amount;
     				health += maxHealth * part;
    @@ -1702,22 +1710,43 @@
     		if (isDead) {
     			return false;
     		}
    -		const float part = amount / buildTime;
    +
     		if (luaRules && !luaRules->AllowUnitBuildStep(builder, this, part)) {
     			return false;
     		}
    +
     		restTime = 0;
    +
    +		if (!AllowedReclaim(builder)) {
    +			builder->DependentDied(this);
    +			return false;
    +		}
    +
    +		const float energyUseScaled = energyUse * modInfo.reclaimUnitEnergyCostFactor;
    +	  
    +		if (!builder->UseEnergy(-energyUseScaled)) {
    +			gs->Team(builder->team)->energyPull += energyUseScaled;
    +			return false;
    +		}
    +
    +		if ((modInfo.reclaimUnitMethod == 0) && (!beingBuilt)) {
    +			beingBuilt = true;
    +		}
    +
     		health += maxHealth * part;
     		if (beingBuilt) {
    -			builder->AddMetal(metalCost*-part);
    +			builder->AddMetal(-metalUse * modInfo.reclaimUnitEfficiency);
     			buildProgress+=part;
     			if(buildProgress<0 || health<0){
     				KillUnit(false, true, NULL);
     				return false;
     			}
    -		} else {
    +		}
    +
    +		
    +		else {
     			if (health < 0) {
    -				builder->AddMetal(metalCost);
    +				builder->AddMetal(metalCost * modInfo.reclaimUnitEfficiency);
     				KillUnit(false, true, NULL);
     				return false;
     			}
    @@ -1890,7 +1919,20 @@
     	}
     }
     
    +bool CUnit::AllowedReclaim (CUnit *builder)
    +{
    +	// Don't allow the reclaim if the unit is finished and we arent allowed to reclaim it
    +	if (!beingBuilt) {
    +		if (allyteam == builder->allyteam) {
    +			if ((team != builder->team) && (!modInfo.reclaimAllowAllies)) return false;
    +		} else {
    +			if (!modInfo.reclaimAllowEnemies) return false;
    +		}
    +	}
     
    +	return true;
    +}
    +
     bool CUnit::UseMetal(float metal)
     {
     	if (metal < 0) {
    Index: rts/Sim/Units/UnitTypes/Builder.cpp
    ===================================================================
    --- rts/Sim/Units/UnitTypes/Builder.cpp	(revision 6162)
    +++ rts/Sim/Units/UnitTypes/Builder.cpp	(working copy)
    @@ -288,7 +288,7 @@
     			}
     			else {
     				// Corpse has been restored, begin resurrection
    -				if (UseEnergy(ud->energyCost * resurrectSpeed / ud->buildTime * 0.5f)) {
    +				if (UseEnergy(ud->energyCost * resurrectSpeed / ud->buildTime * modInfo.resurrectEnergyCostFactor)) {
     					curResurrect->resurrectProgress+=resurrectSpeed/ud->buildTime;
     					CreateNanoParticle(curResurrect->midPos,curResurrect->radius*0.7f,gs->randInt()&1);
     				}
    @@ -314,25 +314,38 @@
     	}
     	else if(curCapture && f3Dist(curCapture->pos, pos)<buildDistance+curCapture->radius && inBuildStance){
     		if(curCapture->team!=team){
    -			curCapture->captureProgress+=1.0f/(150+curCapture->buildTime/captureSpeed*(curCapture->health+curCapture->maxHealth)/curCapture->maxHealth*0.4f);
    -			CreateNanoParticle(curCapture->midPos,curCapture->radius*0.7f,false);
    -			if(curCapture->captureProgress > 1.0f){
    -				if (!curCapture->ChangeTeam(team, CUnit::ChangeCaptured)) {
    -					// capture failed
    -					ENTER_MIXED;
    -					if (team == gu->myTeam) {
    -						logOutput.Print("%s: Capture failed, unit type limit reached", unitDef->humanName.c_str());
    -						logOutput.SetLastMsgPos(pos);
    +
    +			float captureProgressTemp = curCapture->captureProgress + 1.0f/(150+curCapture->buildTime/captureSpeed*(curCapture->health+curCapture->maxHealth)/curCapture->maxHealth*0.4f);
    +			if (captureProgressTemp >= 1.0f) {
    +				captureProgressTemp = 1.0f;
    +			}
    +	
    +			const float captureFraction = captureProgressTemp - curCapture->captureProgress;
    +			const float energyUseScaled = curCapture->energyCost * captureFraction * modInfo.captureEnergyCostFactor;
    +
    +			if (!UseEnergy(energyUseScaled)) {
    +				gs->Team(team)->energyPull += energyUseScaled;
    +			} else {
    +				curCapture->captureProgress = captureProgressTemp;
    +				CreateNanoParticle(curCapture->midPos,curCapture->radius*0.7f,false);
    +				if(curCapture->captureProgress > 1.0f){
    +					if (!curCapture->ChangeTeam(team, CUnit::ChangeCaptured)) {
    +						// capture failed
    +						ENTER_MIXED;
    +						if (team == gu->myTeam) {
    +							logOutput.Print("%s: Capture failed, unit type limit reached", unitDef->humanName.c_str());
    +							logOutput.SetLastMsgPos(pos);
    +						}
    +						ENTER_SYNCED;
    +					} else {
    +						// capture succesful
    +						int oldLineage = curCapture->lineage;
    +						curCapture->lineage = this->lineage;
    +						gs->Team(oldLineage)->LeftLineage(curCapture);
     					}
    -					ENTER_SYNCED;
    -				} else {
    -					// capture succesful
    -					int oldLineage = curCapture->lineage;
    -					curCapture->lineage = this->lineage;
    -					gs->Team(oldLineage)->LeftLineage(curCapture);
    +					curCapture->captureProgress=0.0f;
    +					StopBuild(true);
     				}
    -				curCapture->captureProgress=0.0f;
    -				StopBuild(true);
     			}
     		} else {
     			StopBuild(true);
    Index: rts/Sim/Units/Unit.h
    ===================================================================
    --- rts/Sim/Units/Unit.h	(revision 6162)
    +++ rts/Sim/Units/Unit.h	(working copy)
    @@ -113,6 +113,7 @@
     	virtual void Init(const CUnit* builder);
     	bool SetGroup(CGroup* group);
     
    +	bool AllowedReclaim(CUnit *builder);
     	bool UseMetal(float metal);
     	void AddMetal(float metal);
     	bool UseEnergy(float energy);
    Index: rts/Sim/ModInfo.cpp
    ===================================================================
    --- rts/Sim/ModInfo.cpp	(revision 6162)
    +++ rts/Sim/ModInfo.cpp	(working copy)
    @@ -60,7 +60,25 @@
     	const LuaTable reclaimTbl = root.SubTable("reclaim");
     	multiReclaim  = reclaimTbl.GetInt("multiReclaim",  0);
     	reclaimMethod = reclaimTbl.GetInt("reclaimMethod", 1);
    +	reclaimUnitMethod = reclaimTbl.GetInt("unitMethod", 1);
    +	reclaimUnitEnergyCostFactor = reclaimTbl.GetFloat("unitEnergyCostFactor", 0.0);
    +	reclaimUnitEfficiency = reclaimTbl.GetFloat("unitEfficiency", 1.0);
    +	reclaimFeatureEnergyCostFactor = reclaimTbl.GetFloat("featureEnergyCostFactor", 0.0);
    +	reclaimAllowEnemies = reclaimTbl.GetBool("allowEnemies", true);
    +	reclaimAllowAllies = reclaimTbl.GetBool("allowAllies", true);
     
    +	// repair
    +	const LuaTable repairTbl = root.SubTable("repair");
    +	repairEnergyCostFactor = repairTbl.GetFloat("energyCostFactor", 0.0);
    +
    +	// resurrect
    +	const LuaTable resurrectTbl = root.SubTable("resurrect");
    +	resurrectEnergyCostFactor  = resurrectTbl.GetFloat("energyCostFactor",  0.5);
    +
    +	// capture
    +	const LuaTable captureTbl = root.SubTable("capture");
    +	captureEnergyCostFactor = captureTbl.GetFloat("energyCostFactor", 0.0);
    +
     	// fire-at-dead-units
     	const LuaTable fireAtDeadTbl = root.SubTable("fireAtDead");
     	fireAtKilled   = fireAtDeadTbl.GetBool("fireAtKilled", false);
    Index: rts/Sim/Features/Feature.cpp
    ===================================================================
    --- rts/Sim/Features/Feature.cpp	(revision 6162)
    +++ rts/Sim/Features/Feature.cpp	(working copy)
    @@ -306,15 +306,24 @@
     			return false;
     		}
     
    -		reclaimLeft -= part;
    -
    +		float reclaimLeftTemp = reclaimLeft - part;
     		// stop the last bit giving too much resource
    -		if (reclaimLeft < 0) {
    -			reclaimLeft = 0;
    +		if (reclaimLeftTemp < 0) {
    +			reclaimLeftTemp = 0;
     		}
     
    -		const float fractionReclaimed = oldReclaimLeft - reclaimLeft;
    +		const float fractionReclaimed = oldReclaimLeft - reclaimLeftTemp;
    +		const float metalFraction = def->metal * fractionReclaimed;
    +		const float energyFraction = def->energy * fractionReclaimed;
    +		const float energyUseScaled = metalFraction * modInfo.reclaimFeatureEnergyCostFactor;
     
    +		if (!builder->UseEnergy(energyUseScaled)) {
    +			gs->Team(builder->team)->energyPull += energyUseScaled;
    +			return false;
    +		}
    +
    +		reclaimLeft = reclaimLeftTemp;
    +
     		if ((modInfo.reclaimMethod == 1) && (reclaimLeft == 0)) {
     			// All-at-end method
     			builder->AddMetal(def->metal);
    @@ -322,8 +331,8 @@
     		}
     		else if (modInfo.reclaimMethod == 0) {
     			// Gradual reclaim
    -			builder->AddMetal(def->metal * fractionReclaimed);
    -			builder->AddEnergy(def->energy * fractionReclaimed);
    +			builder->AddMetal(metalFraction);
    +			builder->AddEnergy(energyFraction);
     		}
     		else {
     			// Chunky reclaiming, work out how many chunk boundaries we crossed
    
    diff file icon energy_costs2.diff (13,165 bytes) 2008-07-16 08:33 +

-Relationships
+Relationships

-Notes

~0002421

det (reporter)

Added more options to patch, don't apply energy_costs.patch, apply energy_costs2.diff instead.

The full changelog now reads as follows:

This patch adds the following new tags to modrules.{lua,tdf}

repair.energyCostFactor: Used to determine the energy cost used to repair a unit. Defaults to 0.0, which is backwards compatible behavior.

capture.energyCostFactor: Used to determine the energy cost used to capture a unit. Defaults to 0.0, which is backwards compatible behavior.

resurrect.energyCostFactor: Used to determine the energy cost used to resurrect a unit. Defaults to 0.5, which is backwards compatible behavior.

reclaim.unitEnergyCostFactor: Used to determine the energy cost used to reclaim a live or under construction unit. Defaults to 0.0, which is backwards compatible behaviour.

reclaim.featureEnergyCostFactor: Used to determine the energy cost used to reclaim a feature. Defaults to 0.0, which is backwards compatible behavior.

reclaim.unitMethod: Used to determine the method for reclaiming live units. 0 = Revert to nano-frame and do gradual reclaim. 1 = Old method of subtracting HP. Defaults to 1, which is backwards compatible behaviour.

reclaim.unitEfficiency: Used to determine how much metal you get back for reclaiming units (not features, corpses). Defaults to 1.0, which is backwards compatible behaviour.

reclaim.allowEnemies: Whether or not you are allowed to reclaim a living enemy unit. Defaults to true, which is backwards compatible behaviour.

reclaim.allowAllies: Whether or not you are allowed to reclaim a living ally unit. Defaults to true, which is backwards compatible behaviour.

~0002422

imbaczek (reporter)

shouldn't those values be available to LuaUI/LuaRules somewhere?

~0002678

imbaczek (reporter)

wasn't this committed?

~0002679

det (reporter)

It was commited in http://trac.springhq.org/changeset/6188
I don't think I have the ability to close this ticket.
+Notes

-Issue History
Date Modified Username Field Change
2008-07-13 15:25 det New Issue
2008-07-13 15:26 det File Added: energy_costs.patch
2008-07-16 08:33 det File Added: energy_costs2.diff
2008-07-16 08:44 det Note Added: 0002421
2008-07-16 23:13 imbaczek Note Added: 0002422
2008-10-04 21:29 tvo Summary New modrules tags to let {repair,reclaim,capture} cost energy => [PATCH] New modrules tags to let {repair,reclaim,capture} cost energy
2008-10-04 22:41 imbaczek Note Added: 0002678
2008-10-04 22:50 det Note Added: 0002679
2008-10-04 23:59 imbaczek Status new => closed
2008-10-04 23:59 imbaczek Resolution open => fixed
2008-10-04 23:59 imbaczek Fixed in Version => 0.76b1+svn
+Issue History