Skip to content

Commit

Permalink
Fixing a factory calculation bug and fixing #269
Browse files Browse the repository at this point in the history
Fixed factory rate to build extra buildings was always too low as didn't take account of building cost vs income correctly.

Also fixed minimum qty must be more than 3 units to even consider factories.
  • Loading branch information
SMUnlimited committed May 20, 2024
1 parent a07dc2c commit 94ce65c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- AMAI now takes direct control of alliance targets instead of using the hardcoded logic. This will enable better control and allow us to ignore the alliance target in some situations.

### Fixed
- Fixed factory rate to build extra buildings was always too low as didn't take account of building cost vs income correctly.
- Fixed issue with boolean check of third mine timing.
- Fixed issue where mine required for ancient or item expansions could be nulled mid use which would break the logic. (jzy-chitong56)
- Fixed Mark of Talon upgrade only requires adept training from 1.36.1 war3 patch.
Expand Down
17 changes: 10 additions & 7 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ globals
integer total_food = 0
integer wood_buffer = 0
real gold_income = 0
integer income_per_mine = 3000
integer income_per_mine = 50
real gold_unit_percentage = 0.9
boolean take_all_ghouls_along = false

Expand Down Expand Up @@ -8212,7 +8212,7 @@ function InitBuildArrayAM takes nothing returns nothing
set build_length = 0
loop
exitwhen i >= building_length
set income_percentage[building[i]] = 1 / I2R(building_length)
set income_percentage[building[i]] = 0
set i = i + 1
endloop
call ReleaseBuildLock()
Expand Down Expand Up @@ -9025,28 +9025,31 @@ function GetMinesHarvested takes nothing returns integer
endfunction

//============================================================================
// Total excepted income per second (plus spare gold)
function GetGoldIncome takes nothing returns real
local integer inc = GetMinesHarvested()*income_per_mine
if inc > GetGoldOwned() then
set inc = GetGoldOwned()
endif
return I2R(inc + GetGold())/300
return I2R(inc + GetGold())
endfunction

//============================================================================
function GetIncomePercentage takes integer qty returns real
if qty == 0 then
if qty <= 3 then
return 0.0
endif
return 1 - 1/I2R(qty)
endfunction

//============================================================================
// in_percent = gold cost building / income rate
// gold_income = (GetGoldRate of mines + current gold) * 0.9
function GetFactoryQty takes integer qty, integer build_time, integer gold_cost, real in_percentage returns integer
local real gip = GetIncomePercentage(qty) * gold_income * in_percentage
local real gip = GetIncomePercentage(qty) * gold_income * (1-in_percentage)
local real gic = I2R(Max(gold_cost,1))/I2R(Max(build_time, 1))
// call DisplayToAll("factory number returned: "+Int2Str(Max(Min(R2I(gip/gic), difficulty),1)))
return Max(Min(R2I(gip/gic), difficulty),1)
return Max(Min(R2I(gip/gic), difficulty),1) // Difficulty no more than 3 on insane, 2 on normal
endfunction

//============================================================================
Expand Down Expand Up @@ -11106,7 +11109,7 @@ function FactoryNumberUpdate takes nothing returns nothing
loop
exitwhen i >= building_length
set j = building[i]
set income_percentage[j] = I2R(gold_sum[j]) / I2R(g_sum)
set income_percentage[j] = I2R(gold_sum[j]) / gold_income
if build_num[j] > 0 then
call BuildUnit(GetFactoryQty(build_num[j], build_time_sum[j] / build_num[j], gold_sum[j] / build_num[j], income_percentage[j]), j, prio_sum[j] / build_num[j])
endif
Expand Down

0 comments on commit 94ce65c

Please sign in to comment.