void PageUnit::OnChangedType(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // TODO: Add your control notification handler code here int index = pNMListView->iItem; if(index == -1) { return; } int nID = m_UnitTypeList.GetItemData(index); UnitTypeID Id = static_cast<UnitTypeID>(nID); UnitType *pUnitType = NULL; UnitString *pSymbol = NULL; if(m_pUnitSystem->FindUnit(Id,pUnitType)) { if(!UpdataSymbol()) return; m_UnitTypeList.SetHotItem(index); m_CurSel = index; m_pCurUnit = pUnitType; m_symbolList.ResetContent(); IteratorPtr<UnitString> iteratorPtr(pUnitType->CreatIterator()); for(iteratorPtr->Fist();!iteratorPtr->IsDone();iteratorPtr->Next()) { pSymbol = &iteratorPtr->CurrentItem(); InitSymbol(pSymbol); } } else { ASSERT(FALSE); } *pResult = 0; }
Corners BuildingPlacer::getCorners(UnitType type, TilePosition center) { int x1 = center.x; int y1 = center.y; int x2 = x1 + type.tileWidth() - 1; int y2 = y1 + type.tileHeight() - 1; int margin = 0; if (type.canProduce()) margin = 1; if (type.getID() == UnitTypes::Terran_Bunker.getID()) margin = 1; x1 -= margin; x2 += margin; y1 -= margin; y2 += margin; //Special case: Terran Addon buildings //Add 2 extra spaces to the right to make space for the addons. if (BaseAgent::isOfType(type, UnitTypes::Terran_Factory) || BaseAgent::isOfType(type, UnitTypes::Terran_Starport) || BaseAgent::isOfType(type, UnitTypes::Terran_Command_Center) || BaseAgent::isOfType(type, UnitTypes::Terran_Science_Facility)) { x2 += 2; } Corners c; c.x1 = x1; c.y1 = y1; c.x2 = x2; c.y2 = y2; return c; }
void Evaluation::calculate_enemy() { enemy.clear(); map<int, unit_info> enemy_info = DecisionMaker::Instance().getStatistics().enemy(); for (auto iter : enemy_info) { UnitType t = iter.second.type; int hp = iter.second.hit_points; switch (t) { //invisible unit case Protoss_Dark_Templar: hp = t.maxHitPoints() + t.maxShields(); //protoss ground unit case Protoss_Zealot: case Protoss_Dragoon: case Protoss_Archon: //terran ground unit case Terran_Marine: case Terran_Firebat: case Terran_Ghost: case Terran_Vulture: case Terran_Siege_Tank_Tank_Mode: case Terran_Siege_Tank_Siege_Mode: case Terran_Goliath: //zerg ground unit case Zerg_Zergling: case Zerg_Hydralisk: case Zerg_Ultralisk: //protess air unit case Protoss_Scout: case Protoss_Arbiter: case Protoss_Corsair: //terran air unit case Terran_Wraith: case Terran_Battlecruiser: case Terran_Valkyrie: //zerg air unit case Zerg_Mutalisk: case Zerg_Guardian: case Zerg_Devourer: case Zerg_Scourge: single_eval(Broodwar->enemy(), t, hp); break; default: break; } } }
//--------------------------------------------- ARMOR ------------------------------------------------------ int PlayerInterface::armor(UnitType unit) const { int armor = unit.armor(); armor += getUpgradeLevel(unit.armorUpgrade()); if ( unit == UnitTypes::Zerg_Ultralisk && getUpgradeLevel(UpgradeTypes::Chitinous_Plating) > 0 ) armor += 2; else if ( unit == UnitTypes::Hero_Torrasque ) armor += 2; return armor; }
bool __fastcall Shared_unitInWpnRange_callback(Unit *uIterator) { // Unit check and unit status if ( uIterator == unitsInWpnRange_Unit || uIterator->isInvincible() ) return false; // Weapon distance check int dist = unitsInWpnRange_Unit->getDistance(uIterator); if ( (unitsInWpnRange_Wpn.minRange() && dist < unitsInWpnRange_Wpn.minRange()) || dist > unitsInWpnRange_Max ) return false; // Weapon behavioural checks UnitType ut = uIterator->getType(); if ( (( unitsInWpnRange_Wpn.targetsOwn() && uIterator->getPlayer() != unitsInWpnRange_Unit->getPlayer() ) || ( !unitsInWpnRange_Wpn.targetsAir() && (!uIterator->isLifted() && !ut.isFlyer()) ) || ( !unitsInWpnRange_Wpn.targetsGround() && (uIterator->isLifted() || ut.isFlyer()) ) || ( unitsInWpnRange_Wpn.targetsMechanical() && ut.isMechanical() ) || ( unitsInWpnRange_Wpn.targetsOrganic() && ut.isOrganic() ) || ( unitsInWpnRange_Wpn.targetsNonBuilding() && !ut.isBuilding() ) || ( unitsInWpnRange_Wpn.targetsNonRobotic() && !ut.isRobotic() ) || ( unitsInWpnRange_Wpn.targetsOrgOrMech() && (ut.isOrganic() || ut.isMechanical()) )) ) return false; return true; }
int MovementModel::admits(const UnitType& unit_type, const Tile& tile) const { if (unit_type.has_property(Walking) && tile.has_property(Walkable)) return true; else if (unit_type.has_property(Swimming) && tile.has_property(Swimmable)) return true; else if (unit_type.has_property(Sailing) && tile.has_property(Sailable)) return true; if (unit_type.has_property(Flying) && tile.has_property(Flyable)) return true; return false; }
BWAPI::Unit *UnitWrap::FindNewAttackTarget() const { UnitType t = pUnit->getType(); Unit *pTarg = pUnit->getClosestUnit( IsEnemy && [this](Unit *u){ return pUnit->isInWeaponRange(u);} && IsVisible && !IsInvincible, std::max(t.seekRange(),t.sightRange())*32 ); // Should be greatly expanded, but for now something simple return pTarg; }
//reserves resources for this unit type pair<int, BuildOrderManager::Resources> BuildOrderManager::reserveResources(MetaUnit* builder, UnitType unitType) { int t=Broodwar->getFrameCount(); if (builder) t=nextFreeTime(builder,unitType); pair<int, Resources> ret; ret.first=t; ret.second.minerals=unitType.mineralPrice(); ret.second.gas=unitType.gasPrice(); reserveResources(ret); return ret; }
void PageUnit::Init(UnitSubSystem *pUnitSystem) { ASSERT(pUnitSystem != NULL); m_pUnitSystem = pUnitSystem; UnitType *pUnitType = NULL; UnitTypeArrayRef &arrayRef = pUnitSystem->GetUnitArray(); for(int i=0; i<arrayRef.GetSize();i++) { pUnitType = arrayRef.GetAt(i); m_UnitTypeList.InsertItem(i,pUnitType->GetName()); m_UnitTypeList.SetItemText(i,1,pUnitType->GetCurSymbol()); m_UnitTypeList.SetItemData(i,pUnitType->GetTypeID()); } }
UnitReference UnitContainer::new_unit(UnitType &type, Player &owner, TerrainObject *other) { auto newobj = std::make_unique<Unit>(*this, next_new_id++); // try placing unit TerrainObject *placed = type.place_beside(newobj.get(), other); if (placed) { type.initialise(newobj.get(), owner); auto id = newobj->id; this->live_units.emplace(id, std::move(newobj)); return this->live_units[id]->get_ref(); } return UnitReference(); // is not valid }
//returns the next available time that the given unit will be able to train the given unit type //takes into account required units //todo: take into account required tech and supply int BuildOrderManager::nextFreeTime(const MetaUnit* unit, UnitType t) { int time=nextFreeTime(unit); for(map<UnitType,int>::const_iterator i=t.requiredUnits().begin();i!=t.requiredUnits().end();i++) { int ntime=nextFreeTime(i->first); if (ntime==-1) return -1; if (ntime>time) time=ntime; if (i->first.isAddon() && i->first.whatBuilds().first==unit->getType() && !unit->hasAddon()) return -1; } return time; }
bool BuildingPlacer::canBuildAt(UnitType toBuild, TilePosition pos) { int maxW = w - toBuild.tileWidth() - 1; int maxH = h - toBuild.tileHeight() - 1; //Out of bounds check if (pos.x >= 0 && pos.x < maxW && pos.y >= 0 && pos.y < maxH) { if (canBuild(toBuild, pos)) { return true; } } return false; }
bool CoverMap::canBuildAt(UnitType toBuild, TilePosition pos) { int maxW = w - toBuild.tileWidth() - 1; int maxH = h - toBuild.tileHeight() - 1; //Out of bounds check if (pos.x() >= 0 && pos.x() < maxW && pos.y() >= 0 && pos.y() < maxH) { if (canBuild(toBuild, pos)) { return true; } } return false; }
string BuildPlanner::format(UnitType type) { string name = type.getName(); int i = name.find(" "); string fname = name.substr(i + 1, name.length()); return fname; }
UnitReference UnitContainer::new_unit(UnitType &type, Player &owner, coord::phys3 position) { auto newobj = std::make_unique<Unit>(*this, next_new_id++); // try placing unit at this location auto terrain_shared = this->get_terrain(); auto placed = type.place(newobj.get(), terrain_shared, position); if (placed) { type.initialise(newobj.get(), owner); auto id = newobj->id; this->live_units.emplace(id, std::move(newobj)); return this->live_units[id]->get_ref(); } return UnitReference(); // is not valid }
void ClientInvade::addUnit(const Position position, const UnitType type) { QJsonObject p; p["position"] = pos2str(position); p["type"] = static_cast<int>(type.id()); sendMessage("addUnit", p); }
void ClientInvade::chooseEffect(Effect effect, UnitType elite) { QJsonObject p; p["effect"] = static_cast<int>(effect); p["elite"] = static_cast<int>(elite.id()); sendMessage("chooseEffect", p); }
bool Squad::needUnit(UnitType type) { //1. Check if prio is set to Inactive squad. if (priority >= 1000) { return false; } int noCreated = 1; if (BuildPlanner::isZerg()) { if (type.isTwoUnitsInOneEgg()) { noCreated = 2; } } //2. Check setup for (int i = 0; i < (int)setup.size(); i++) { if (setup.at(i).equals(type)) { //Found a matching setup, see if there is room if (setup.at(i).current + BuildPlanner::Instance().noInProduction(type) + noCreated <= setup.at(i).no) { return true; } } } return false; }
string Constructor::format(UnitType type) { string name = type.getName(); int i = name.find("_"); string fname = name.substr(i + 1, name.length()); return fname; }
//---------------------------------------------------------------------------------------------- MapArea StarCraftMap::GetSpecialBuildingPosition(EntityClassType p_buildingType) const { if (!m_isOnline) DEBUG_THROW(InvalidOperationException(XcptHere)); MapArea candidatePosition = MapArea::Null(); // Get the player base tile position MapArea colony = g_Game->Self()->GetColonyMapArea(); Vector2 colonyTile = colony.Pos(); // Get the unit type object UnitType type; TID unitTypeId; string typeName; unitTypeId = g_Database.EntityMapping.GetBySecond(p_buildingType); typeName = g_Database.EntityIdentMapping.GetByFirst(unitTypeId); type = BWAPI::UnitType::getType(typeName); if (type.isRefinery()) { int bestDistance = INT_MAX; Unitset geysers = Broodwar->getGeysers(); Unit currentGeyser; for (unsigned i = 0; i < geysers.size(); ++i) { currentGeyser = geysers[i]; Vector2 currentPosition = Vector2( UnitPositionFromTilePosition(currentGeyser->getTilePosition().x), UnitPositionFromTilePosition(currentGeyser->getTilePosition().y)); int currentDistance = colonyTile.Distance(currentPosition); if (currentDistance <= bestDistance) { bestDistance = currentDistance; candidatePosition = MapArea( currentPosition, type.tileWidth(), type.tileHeight()); } } _ASSERTE(CanBuildHere(candidatePosition.Pos(), p_buildingType)); } return candidatePosition; }
bool BuildPlanner::supplyBeingBuilt() { //Zerg if (isZerg()) { if (noInProduction(UnitTypes::Zerg_Overlord) > 0) { return true; } else { return false; } } //Terran and Protoss UnitType supply = Broodwar->self()->getRace().getSupplyProvider(); //1. Check if we are already building a supply vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents(); for (int i = 0; i < (int)agents.size(); i++) { BaseAgent* agent = agents.at(i); if (agent->isAlive()) { if (agent->getUnitType().getID() == supply.getID()) { if (agent->getUnit()->isBeingConstructed()) { //Found one that is being constructed return true; } } } } //2. Check if we have a supply in build queue for (int i = 0; i < (int)buildQueue.size(); i++) { if (buildQueue.at(i).toBuild.getID() == supply.getID()) { return true; } } return false; }
Unit( Id const& id, UnitType const& type ): id(id), type(&type), space_left(type.get_space()) {}
bool AgentFactory::isOfType(Unit* unit, UnitType type) { if (unit->getType().getID() == type.getID()) { return true; } return false; }
bool TargetingAgent::canAttack(UnitType type) { if (type.isBuilding()) { if (type.canAttack()) return true; return false; } if (type.isAddon()) { return false; } if (type.isWorker()) { return false; } return true; }
Unit* TargetingAgent::findTarget(BaseAgent* agent) { //Check if the agent targets ground and/or air bool targetsGround = false; if (agent->getUnitType().groundWeapon().targetsGround()) targetsGround = true; if (agent->getUnitType().airWeapon().targetsGround()) targetsGround = true; bool targetsAir = false; if (agent->getUnitType().groundWeapon().targetsAir()) targetsAir = true; if (agent->getUnitType().airWeapon().targetsAir()) targetsAir = true; //Check max range int range = agent->getUnitType().seekRange(); if (agent->getUnit()->isSieged()) range = agent->getUnit()->getType().groundWeapon().maxRange(); //Iterate through enemies to select a target int bestTargetScore = -1; Unit* target = NULL; for(set<Unit*>::const_iterator i=Broodwar->enemy()->getUnits().begin();i!=Broodwar->enemy()->getUnits().end();i++) { UnitType t = (*i)->getType(); bool canAttack = false; if (!t.isFlyer() && targetsGround) canAttack = true; if ((t.isFlyer() || (*i)->isLifted()) && targetsAir) canAttack = true; if ((t.hasPermanentCloak() || (*i)->isBurrowed()) && !(*i)->isDetected()) canAttack = false; if (canAttack) { int d = (int)agent->getUnit()->getDistance((*i)); if (d <= range) { int cScore = (int)((double)t.destroyScore() * getTargetModifier(agent->getUnit()->getType(), t)); if (cScore > bestTargetScore) { bestTargetScore = cScore; target = (*i); } } } } return target; }
bool Constructor::containsType(UnitType type) { for (int i = 0; i < (int)buildPlan.size(); i++) { if (buildPlan.at(i).getID() == type.getID()) { return true; } } for (int i = 0; i < (int)buildQueue.size(); i++) { if (buildQueue.at(i).toBuild.getID() == type.getID()) { return true; } } return false; }
void SquadFileReader::addUnit(string line) { Tokens token = split(line, ":"); //Replace all _ with whitespaces, or they wont match replace(token.key); UnitType type = getUnitType(token.key); if (type.getID() != UnitTypes::Unknown.getID()) { int no = toInt(token.value); cSquad->addSetup(type, toInt(token.value)); return; } //No UnitType match found Broodwar->printf("Error: No matching UnitType found for %s", token.key.c_str()); }
void ZergBuildPlanner::unlock(UnitType type) { for (vector<UnitType>::iterator it = buildOrder.begin(); it != buildOrder.end(); it++) { if (it->getID() == type.getID()) { locked = false; buildOrder.erase(it); return; } } }
bool BuildingPlacer::isDefenseBuilding(UnitType toBuild) { int bId = toBuild.getID(); if (bId == UnitTypes::Terran_Bunker.getID()) return true; if (bId == UnitTypes::Protoss_Photon_Cannon.getID()) return true; if (bId == UnitTypes::Zerg_Creep_Colony.getID()) return true; return false; }
bool BuildingPlacer::suitableForDetector(TilePosition pos) { Agentset agents = AgentManager::getInstance()->getAgents(); for (auto &a : agents) { UnitType type = a->getUnitType(); if (a->isAlive() && type.isDetector() && type.isBuilding()) { double dRange = type.sightRange() * 1.6; double dist = a->getUnit()->getPosition().getDistance(Position(pos)); if (dist <= dRange) { return false; } } } return true; }