/** ** Find Resource. ** ** @param unit The unit that wants to find a resource. ** @param startUnit Find closest unit from this location ** @param range Maximum distance to the resource. ** @param resource The resource id. ** ** @note This will return an usable resource building that doesn't ** belong to the player or one of his allies. ** ** @return NULL or resource unit */ CUnit *UnitFindResource(const CUnit &unit, const CUnit &startUnit, int range, int resource, //Wyrmgus start // bool check_usage, const CUnit *deposit) bool check_usage, const CUnit *deposit, bool mine_on_top) //Wyrmgus end { if (!deposit) { // Find the nearest depot deposit = FindDepositNearLoc(*unit.Player, startUnit.tilePos, range, resource); } TerrainTraversal terrainTraversal; terrainTraversal.SetSize(Map.Info.MapWidth, Map.Info.MapHeight); terrainTraversal.Init(); terrainTraversal.PushUnitPosAndNeighboor(startUnit); CUnit *resultMine = NULL; //Wyrmgus start // ResourceUnitFinder resourceUnitFinder(unit, deposit, resource, range, check_usage, &resultMine); ResourceUnitFinder resourceUnitFinder(unit, deposit, resource, range, check_usage, &resultMine, mine_on_top); //Wyrmgus end terrainTraversal.Run(resourceUnitFinder); return resultMine; }
void AiNewDepotRequest(CUnit &worker) { /* DebugPrint("%d: Worker %d report: Resource [%d] too far from depot, returning time [%d].\n" _C_ worker->Player->Index _C_ worker->Slot _C_ worker->CurrentResource _C_ worker->Data.Move.Cycles ); */ Vec2i pos = {-1, -1}; ResourceInfo *resinfo = worker.Type->ResInfo[worker.CurrentResource]; if (resinfo->TerrainHarvester) { pos = worker.CurrentOrder()->Arg1.Resource.Pos; } else { CUnit *mine = worker.CurrentOrder()->Arg1.Resource.Mine; if (mine) { pos = mine->tilePos; } } if (pos.x != -1 && NULL != FindDepositNearLoc(worker.Player, pos.x, pos.y, 10, worker.CurrentResource)) { /* * New Depot has just be finished and worker just return to old depot * (far away) from new Deopt. */ return; } CUnitType *best_type = NULL; int best_cost = 0; //int best_mask = 0; // Count the already made build requests. int counter[UnitTypeMax]; AiGetBuildRequestsCount(worker.Player->Ai, counter); const int n = AiHelpers.Depots[worker.CurrentResource - 1].size(); for (int i = 0; i < n; ++i) { CUnitType &type = *AiHelpers.Depots[worker.CurrentResource - 1][i]; if (counter[type.Slot]) { // Already ordered. return; } if (!AiRequestedTypeAllowed(worker.Player, type)) { continue; } // Check if resources available. //int needmask = AiCheckUnitTypeCosts(type); int cost = 0; for (int c = 1; c < MaxCosts; ++c) { cost += type.Stats[worker.Player->Index].Costs[c]; } if (best_type == NULL || (cost < best_cost)) { best_type = &type; best_cost = cost; //best_mask = needmask; } } if (best_type) { //if(!best_mask) { AiBuildQueue queue; queue.Type = best_type; queue.Want = 1; queue.Made = 0; queue.X = pos.x; queue.Y = pos.y; worker.Player->Ai->UnitTypeBuilt.push_back(queue); DebugPrint("%d: Worker %d report: Requesting new depot near [%d,%d].\n" _C_ worker.Player->Index _C_ worker.Slot _C_ queue.X _C_ queue.Y ); /* } else { AiPlayer->NeededMask |= best_mask; } */ } }
void AiNewDepotRequest(CUnit &worker) { #if 0 DebugPrint("%d: Worker %d report: Resource [%d] too far from depot, returning time [%d].\n" _C_ worker->Player->Index _C_ worker->Slot _C_ worker->CurrentResource _C_ worker->Data.Move.Cycles); #endif Assert(worker.CurrentAction() == UnitActionResource); COrder_Resource &order = *static_cast<COrder_Resource *>(worker.CurrentOrder()); const Vec2i pos = order.GetHarvestLocation(); if (pos.x != -1 && NULL != FindDepositNearLoc(*worker.Player, pos, 10, worker.CurrentResource)) { /* * New Depot has just be finished and worker just return to old depot * (far away) from new Deopt. */ return; } CUnitType *best_type = NULL; int best_cost = 0; //int best_mask = 0; // Count the already made build requests. int counter[UnitTypeMax]; AiGetBuildRequestsCount(*worker.Player->Ai, counter); const int n = AiHelpers.Depots[worker.CurrentResource - 1].size(); for (int i = 0; i < n; ++i) { CUnitType &type = *AiHelpers.Depots[worker.CurrentResource - 1][i]; if (counter[type.Slot]) { // Already ordered. return; } if (!AiRequestedTypeAllowed(*worker.Player, type)) { continue; } // Check if resources available. //int needmask = AiCheckUnitTypeCosts(type); int cost = 0; for (int c = 1; c < MaxCosts; ++c) { cost += type.Stats[worker.Player->Index].Costs[c]; } if (best_type == NULL || (cost < best_cost)) { best_type = &type; best_cost = cost; //best_mask = needmask; } } if (best_type) { //if(!best_mask) { AiBuildQueue queue; queue.Type = best_type; queue.Want = 1; queue.Made = 0; queue.Pos = pos; worker.Player->Ai->UnitTypeBuilt.push_back(queue); DebugPrint("%d: Worker %d report: Requesting new depot near [%d,%d].\n" _C_ worker.Player->Index _C_ UnitNumber(worker) _C_ queue.Pos.x _C_ queue.Pos.y); /* } else { AiPlayer->NeededMask |= best_mask; } */ } }