/** ** Remove unit-type from build list. ** ** @param pai Computer AI player. ** @param type Unit-type which is now available. */ static void AiRemoveFromBuilt(PlayerAi *pai, const CUnitType *type) { int equivalents[UnitTypeMax + 1]; int equivalentsCount; if (AiRemoveFromBuilt2(pai, type)) { return; } // // This could happen if an upgrade is ready, look for equivalent units. // equivalentsCount = AiFindUnitTypeEquiv(type, equivalents); for (int i = 0; i < equivalentsCount; ++i) { if (AiRemoveFromBuilt2(pai, UnitTypes[equivalents[i]])) { return; } } if (pai->Player == ThisPlayer) { DebugPrint("My guess is that you built something under ai me. naughty boy!\n"); return; } Assert(0); }
/** ** Find All unittypes equivalent to a given one, and which are available ** UnitType are returned in the preferred order (ie palladin >> knight...) ** ** @param unittype The unittype to find equivalence for ** @param usableTypes int array which will hold the result. (Size UnitTypeMax+1) ** ** @return the number of unittype found */ int AiFindAvailableUnitTypeEquiv(const CUnitType &unittype, int *usableTypes) { // 1 - Find equivalents int usableTypesCount = AiFindUnitTypeEquiv(unittype, usableTypes); // 2 - Remove unavailable unittypes for (int i = 0; i < usableTypesCount;) { if (!CheckDependByIdent(*AiPlayer->Player, UnitTypes[usableTypes[i]]->Ident)) { // Not available, remove it usableTypes[i] = usableTypes[usableTypesCount - 1]; --usableTypesCount; } else { ++i; } } // 3 - Sort by level std::sort(usableTypes, usableTypes + usableTypesCount, UnitTypePrioritySorter_Decreasing()); return usableTypesCount; }
/** ** Reduce made unit-type from build list. ** ** @param pai Computer AI player. ** @param type Unit-type which is now available. */ void AiReduceMadeInBuilt(PlayerAi &pai, const CUnitType &type) { if (AiReduceMadeInBuilt2(pai, type)) { return; } // This could happen if an upgrade is ready, look for equivalent units. int equivs[UnitTypeMax + 1]; const unsigned int equivnb = AiFindUnitTypeEquiv(type, equivs); for (unsigned int i = 0; i < equivnb; ++i) { if (AiReduceMadeInBuilt2(pai, *UnitTypes[equivs[i]])) { return; } } if (pai.Player == ThisPlayer) { DebugPrint("My guess is that you built something under ai me. naughty boy!\n"); return; } fprintf(stderr, "Can't reduce %s from build list.\n", type.Ident.c_str()); }
/** ** Reduce made unit-type from build list. ** ** @param pai Computer AI player. ** @param type Unit-type which is now available. */ static void AiReduceMadeInBuilt(PlayerAi *pai, const CUnitType *type) { int equivs[UnitTypeMax + 1]; int equivnb; if (AiReduceMadeInBuilt2(pai, type)) { return; } // // This could happen if an upgrade is ready, look for equivalent units. // equivnb = AiFindUnitTypeEquiv(type, equivs); for (size_t i = 0; i < (size_t)equivnb; ++i) { if (AiReduceMadeInBuilt2(pai, UnitTypes[equivs[i]])) { return; } } Assert(0); }