// looks at current power usage, and requirements for unit, and decides if we can build it without stalling // assumes nothing else suddenly starting at same time... // do something more elegant later public bool CanBuild(IUnitDef def) { // if (csai.DebugOn) // { // aicallback.SendTextMsg("metalcontroller canbuild " + def.humanName + " current metal: " + aicallback.GetMetal() + " cost: " + def.metalCost, 0); // } if (aicallback.GetMetal() > def.metalCost) { return(true); } //return aicallback.GetMetal() > def.metalCost; double excessmetalrequired = (def.metalCost - aicallback.GetMetal() * 8 / 10) / def.buildTime; double OurIncome = aicallback.GetMetalIncome() - aicallback.GetMetalUsage(); logfile.WriteLine("Metal income: " + aicallback.GetMetalIncome() + " metal usage: " + aicallback.GetMetalUsage()); bool result = (excessmetalrequired * 4) < OurIncome; logfile.WriteLine("Current metal: " + aicallback.GetMetal() + " itemmetalcost: " + def.metalCost + " buildtime: " + def.buildTime + " excessmetalrequired: " + excessmetalrequired + " our income: " + OurIncome + " overall: " + result); return(result); }