Exemple #1
0
        // 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)
        {
            double excesspowerrequired = (def.energyCost - aicallback.GetEnergy()) / def.buildTime;
            double oursurplus          = aicallback.GetEnergyIncome() - aicallback.GetEnergyUsage();
            // logfile.WriteLine( "Out income: " + aicallback.GetEnergyIncome() + " usage: " + aicallback.GetEnergyUsage() + " surplus: " + oursurplus );
            bool result = excesspowerrequired < oursurplus;

            //logfile.WriteLine( "Current energy: " + aicallback.GetEnergy() + " itemenergycost: " + def.energyCost + " buildtime: " + def.buildTime + " Excesspowerrequired: " + excesspowerrequired + " overall: " + result );
            return(result);
        }