2020-05-30 10:45 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000566Spring engineGeneralpublic2007-08-09 19:48
ReporterKDR_11k 
Assigned Toimbaczek 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000566: [PATCH]Builders don't properly check for the resources they use
DescriptionCUnit::AddBuildPower only checks if enough current metal and energy is present before giving the go ahead to add the build power but the functions used to deduct the resources (CTeam::UseEnergy, CTeam::UseMetal) use a different formula to check if they can deduct, namely:

amount < resource - 10*previousResourceUpkeep (replace "Resource" with the proper resource)

So if

resource - 10*previousResourceUpkeep < amount < resource

the construction will add the build power but the game will not deduct the resources as CTeam::UseEnergy/UseMetal assume there's not enough around.

This patch makes CUnit::AddBuildPower check if CTeam::UseEnergy and UseMetal returned true and not add to the build progress if not. It will also refund the metal that UseMetal deducted if it returned true but UseEnergy didn't.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon noMoreFreeLunch.patch (1,158 bytes) 2007-07-22 15:03 -
    Index: Unit.cpp
    ===================================================================
    --- Unit.cpp	(revision 4026)
    +++ Unit.cpp	(working copy)
    @@ -1594,15 +1594,20 @@
     			if ((gs->Team(builder->team)->metal  >= metalUse) &&
     			    (gs->Team(builder->team)->energy >= energyUse) &&
     			    (!luaRules || luaRules->AllowUnitBuildStep(builder, this, part))) {
    -				builder->UseMetal(metalUse);
    -				builder->UseEnergy(energyUse);
    -				health += (maxHealth * part);
    -				buildProgress += part;
    -				if (buildProgress >= 1.0f) {
    -					if (health > maxHealth) {
    -						health = maxHealth;
    +				if (builder->UseMetal(metalUse)) { //just because we checked doesn't mean they were deducted since upkeep can prevent deduction
    +					if (builder->UseEnergy(energyUse)) {
    +						health += (maxHealth * part);
    +						buildProgress += part;
    +						if (buildProgress >= 1.0f) {
    +							if (health > maxHealth) {
    +								health = maxHealth;
    +							}
    +							FinishedBuilding();
    +						}
     					}
    -					FinishedBuilding();
    +					else {
    +						builder->UseMetal(-metalUse); //refund the metal if the energy cannot be deducted
    +					}
     				}
     				return true;
     			} else {
    
    patch file icon noMoreFreeLunch.patch (1,158 bytes) 2007-07-22 15:03 +

-Relationships
+Relationships

-Notes

~0001060

imbaczek (reporter)

committed in r4169.
+Notes

-Issue History
Date Modified Username Field Change
2007-07-22 15:03 KDR_11k New Issue
2007-07-22 15:03 KDR_11k File Added: noMoreFreeLunch.patch
2007-08-09 19:48 imbaczek Status new => resolved
2007-08-09 19:48 imbaczek Resolution open => fixed
2007-08-09 19:48 imbaczek Assigned To => imbaczek
2007-08-09 19:48 imbaczek Note Added: 0001060
+Issue History