void CommanderBuild(IUnitDef unitdef) { Float3 commanderpos = aicallback.GetUnitPos(commanderid); IUnitDef corasydef = buildtable.UnitDefByName["CORGANT".ToLower()] as IUnitDef; Float3 buildsite = aicallback.ClosestBuildSite(corasydef, commanderpos, 1400.0, 2); buildsite = aicallback.ClosestBuildSite(unitdef, buildsite, 1400.0, 2); CommanderBuildAt(unitdef, buildsite); }
void BuildExtractor( int constructorid ) { IUnitDef unitdef = buildtable.UnitDefByName[ BuildTable.ArmMex ] as IUnitDef;; Float3 constructorpos = aicallback.GetUnitPos( constructorid ); Float3 nearestmetalpos = metal.GetNearestMetalSpot( constructorpos ); logfile.WriteLine( "BuildExtractor nearestmetalpos is null? " + ( nearestmetalpos == null ).ToString() ); Float3 buildsite = aicallback.ClosestBuildSite( unitdef, nearestmetalpos, 1400.0, 2 ); BuildAt( constructorid, unitdef, buildsite ); }
public void UnitCreated(int unit) { aicallback.SendTextMsg("Unit created: " + unit, 0); IUnitDef unitdef = aicallback.GetUnitDef(unit); aicallback.SendTextMsg("Unit created: " + unitdef.name, 0); IMoveData movedata = unitdef.movedata; if (movedata != null) { aicallback.SendTextMsg("Max Slope: " + movedata.maxSlope, 0); } if (unitdef.isCommander) { int numbuildoptions = unitdef.GetNumBuildOptions(); string buildoptionsstring = "Build options: "; for (int i = 0; i < numbuildoptions; i++) { buildoptionsstring += unitdef.GetBuildOption(i); } aicallback.SendTextMsg(buildoptionsstring, 0); Float3 commanderpos = aicallback.GetUnitPos(unit); aicallback.SendTextMsg("Commanderpos: " + commanderpos.ToString(), 0); int numunitdefs = aicallback.GetNumUnitDefs(); aicallback.SendTextMsg("Num unit defs: " + numunitdefs, 0); for (int i = 1; i <= numunitdefs; i++) { IUnitDef thisunitdef = aicallback.GetUnitDefByTypeId(i); if (thisunitdef.name == "ARMSOLAR") { aicallback.SendTextMsg("Found solar collector def: " + thisunitdef.id, 0); Float3 nearestbuildpos = aicallback.ClosestBuildSite(thisunitdef, commanderpos, 1400, 2); aicallback.SendTextMsg("Closest build site: " + nearestbuildpos.ToString(), 0); aicallback.DrawUnit("ARMSOLAR", nearestbuildpos, 0, 200, aicallback.GetMyAllyTeam(), true, true); aicallback.GiveOrder(unit, new Command(-thisunitdef.id, nearestbuildpos.ToDoubleArray())); } } } }
Float3 BuildUnit(int constructorid, string targetunitname) { csai.DebugSay("workflow, building " + targetunitname); IUnitDef targetunitdef = BuildTable.GetInstance().UnitDefByName[targetunitname]; IUnitDef constructordef = UnitController.GetInstance().UnitDefByDeployedId[constructorid]; if (new UnitDefHelp(aicallback).IsMobile(constructordef)) { logfile.WriteLine("constructor is mobile"); Float3 constructorpos = aicallback.GetUnitPos(constructorid); Float3 buildsite = BuildPlanner.GetInstance().ClosestBuildSite(targetunitdef, constructorpos, 3000, 2); buildsite = aicallback.ClosestBuildSite(targetunitdef, buildsite, 1400, 0); logfile.WriteLine("constructor location: " + constructorpos.ToString() + " Buildsite: " + buildsite.ToString() + " target item: " + targetunitdef.humanName); if (!ActiveConstructors.Contains(constructorid)) { ActiveConstructors.Add(constructorid); } aicallback.DrawUnit(targetunitname.ToUpper(), buildsite, 0.0, 200, aicallback.GetMyAllyTeam(), true, true); GiveOrderWrapper.GetInstance().BuildUnit(constructorid, targetunitname, buildsite); return(buildsite); } else { Float3 factorypos = aicallback.GetUnitPos(constructorid); logfile.WriteLine("factory location: " + factorypos.ToString() + " target item: " + targetunitdef.humanName); if (!ActiveConstructors.Contains(constructorid)) { ActiveConstructors.Add(constructorid); } aicallback.DrawUnit(targetunitdef.name.ToUpper(), factorypos, 0.0, 200, aicallback.GetMyAllyTeam(), true, true); GiveOrderWrapper.GetInstance().BuildUnit(constructorid, targetunitname); return(factorypos); } }