Ejemplo n.º 1
0
void UnitAgent::computeKitingActions()
{
	int range = (int)(unit->getType().groundWeapon().maxRange() - 5);
	if (unit->getType().isFlyer()) range = (int)(unit->getType().airWeapon().maxRange() - 5);
	
	int eCnt = enemyAttackingUnitsWithinRange(range);
	if (eCnt > 0)
	{

		//If Vulture, drop some mines
		if (isOfType(UnitTypes::Terran_Vulture))
		{
			if (Broodwar->self()->hasResearched(TechTypes::Spider_Mines))
			{
				if (unit->getSpiderMineCount() > 0)
				{
					unit->useTech(TechTypes::Spider_Mines, unit->getPosition());
					return;
				}
			}
		}

		unit->rightClick(Position(Broodwar->self()->getStartLocation()));
		return;
	}
	else
	{
		PFManager::getInstance()->computeAttackingUnitActions(this, goal, false, false);
	}
}
Ejemplo n.º 2
0
void HighTemplarAgent::computeActions() {
	int cFrame = Broodwar->getFrameCount();
	if (cFrame - lastFrame < 20) {
		return;
	}
	lastFrame = cFrame;

	bool defensive = false;

	if (isOfType(unit->getType(), UnitTypes::Protoss_Archon)) {
		//High Templar has been transformed to an Archon.
		defensive = false;
	}
	else {
		//High Templar unit, use spells
		defensive = true;
		
		//Out of Energy, see if we can transform to an Archon
		if (unit->getEnergy() <= 50 && enemyUnitsWithinRange(320) > 0) {
			if (!hasCastTransform) {
				BaseAgent* target = findArchonTarget();
				if (target != NULL) {
					unit->useTech(TechTypes::Archon_Warp, target->getUnit());
					hasCastTransform = true;
					Broodwar->printf("[%d] %s uses Summon Archon on %s", unitID, unit->getType().getName().c_str(), target->getUnit()->getType().getName().c_str());
					return;
				}
			}
		}
		
		//TODO: Add unitspecific code here
	}

	PFManager::getInstance()->computeAttackingUnitActions(this, goal, defensive);
}
Ejemplo n.º 3
0
// Convert complex variant types to DOM properties with the help of  QAbstractFormBuilder
// Does not perform a check using  QAbstractFormBuilder::checkProperty().
DomProperty *variantToDomProperty(QAbstractFormBuilder *afb, const QMetaObject *meta,
                                  const QString &pname, const QVariant &v)
{
    const QFormBuilderStrings &strings = QFormBuilderStrings::instance();

    DomProperty *dom_prop = new DomProperty();
    dom_prop->setAttributeName(pname);

    const int pindex = meta->indexOfProperty(pname.toLatin1());
    if (pindex != -1) {
        QMetaProperty meta_property = meta->property(pindex);
        if ((v.type() == QVariant::Int || v.type() == QVariant::UInt) && meta_property.isEnumType()) {
            const QMetaEnum e = meta_property.enumerator();
            if (e.isFlag())
                dom_prop->setElementSet(QString::fromAscii(e.valueToKeys(v.toInt())));
            else
                dom_prop->setElementEnum(QString::fromAscii(e.valueToKey(v.toInt())));
            return dom_prop;
        }
        if (!meta_property.hasStdCppSet() || (isOfType(meta, &QAbstractScrollArea::staticMetaObject) && pname == strings.cursorProperty))
            dom_prop->setAttributeStdset(0);
    }

    // Try simple properties
    if (applySimpleProperty(v, isTranslatable(pname, v, meta), dom_prop))
        return dom_prop;

    // Complex properties
    switch (v.type()) {
    case QVariant::Palette: {
        DomPalette *dom = new DomPalette();
        QPalette palette = qvariant_cast<QPalette>(v);

        palette.setCurrentColorGroup(QPalette::Active);
        dom->setElementActive(afb->saveColorGroup(palette));

        palette.setCurrentColorGroup(QPalette::Inactive);
        dom->setElementInactive(afb->saveColorGroup(palette));

        palette.setCurrentColorGroup(QPalette::Disabled);
        dom->setElementDisabled(afb->saveColorGroup(palette));

        dom_prop->setElementPalette(dom);
    } break;
    case QVariant::Brush:
        dom_prop->setElementBrush(afb->saveBrush(qvariant_cast<QBrush>(v)));
        break;
    default:
        delete dom_prop;
        if (afb->resourceBuilder()->isResourceType(v)) {
            dom_prop = afb->resourceBuilder()->saveResource(afb->workingDirectory(), v);
            if (dom_prop)
                dom_prop->setAttributeName(pname);
            break;
        }
        uiLibWarning(msgCannotWriteProperty(pname, v));
        return 0;
    }
    return dom_prop;
}
Ejemplo n.º 4
0
static bool isTranslatable(const QString &pname, const QVariant &v, const QMetaObject *meta)
{
    const QFormBuilderStrings &strings = QFormBuilderStrings::instance();
    if (pname == strings.objectNameProperty)
        return false;
    if (pname == strings.styleSheetProperty && v.type() == QVariant::String && isOfType(meta, &QWidget::staticMetaObject))
        return false;
    return true;
}
Ejemplo n.º 5
0
		Road::RoadType Way::getRoadType()
		{
			Road::RoadType type = Road::ROAD_TYPE_UNKNOWN;
			if(!isWalkable())
				return type;

			try 
			{
				if(isOfType(TAG_BRIDGE))
					type = Road::ROAD_TYPE_BRIDGE;
				else if(isOfType(TAG_TUNNEL))
					type = Road::ROAD_TYPE_TUNNEL;
				else
				{
					std::string highway = getTag(TAG_HIGHWAY);
					std::map<std::string,Road::RoadType>::iterator it = highwayTypes.find(highway);
					if(it != highwayTypes.end())
						type = it->second;
				}
			}
			catch(Exception e) {}

			return type;
		}
Ejemplo n.º 6
0
bool MedicAgent::isMedicTarget(Unit* mUnit)
{
	if (!mUnit->getType().isOrganic())
	{
		//Can only heal organic units
		return false;
	}

	if (mUnit->getType().isWorker())
	{
		//We can heal workers, but no point
		//in following them
		return false;
	}

	if (!mUnit->getType().canAttack())
	{
		//Dont follow units that cant attack
		return false;
	}

	if (isOfType(mUnit, UnitTypes::Terran_Medic))
	{
		//Dont follow other medics
		return false;
	}

	if (mUnit->isLoaded())
	{
		//Dont "follow" bunkered units
		return false;
	}

	//Check if the unit is exploring, then dont follow it.
	BaseAgent* agent = AgentManager::getInstance()->getAgent(mUnit->getID());
	if (agent->isExploring())
	{
		return false;
	}
	return true;
}
void OPMException::viewError()
{
 OString   err;
 PERRINFO  pErrInfoBlk;
 PSZ       pszOffset;
 CHAR      ErrBuffer[512];

 err <<  OMessage(190, OCL::MSGFILE);
 err +   "\n";
 err +   OMessage(191, OCL::MSGFILE, Source);
 sprintf(ErrBuffer, "%d", Line);
 err +   OMessage(192, OCL::MSGFILE, ErrBuffer);
 err +   OMessage(193, OCL::MSGFILE, isOfType());
 sprintf(ErrBuffer, "%d", rc);
 err +   OMessage(194, OCL::MSGFILE, ErrBuffer);
 sprintf(ErrBuffer, "%d", WinGetLastError(OApp::current().anchor()));
 err +   OMessage(197, OCL::MSGFILE, ErrBuffer);

 strcpy(ErrBuffer, "");

 while((pErrInfoBlk = WinGetErrorInfo(OApp::current().anchor())) != (PERRINFO)NULL)
  {
   pszOffset = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
   strcat(ErrBuffer, (((PSZ)pErrInfoBlk) + *((PSHORT)pszOffset)));
   WinFreeErrorInfo(pErrInfoBlk);
  }

 err +   OMessage(198, OCL::MSGFILE, ErrBuffer);

 if (!description) 
  description << OMessage(190, OCL::MSGFILE);

 err +   OMessage(195, OCL::MSGFILE, "\n", description);

 exMsg.error("Note!", err);
}
Ejemplo n.º 8
0
 bool isRightType( std::istream &file )
 {
   return isOfType( file, "SMAT" );
 }
Ejemplo n.º 9
0
BaseAgent* AgentFactory::createProtossAgent(Unit* unit)
{
	if (unit->getType().isWorker())
	{
		return new WorkerAgent(unit);
	}
	else if (unit->getType().isBuilding())
	{
		//Add agents for special buildings here
		if (isOfType(unit, UnitTypes::Protoss_Nexus))
		{
			return new NexusAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Assimilator))
		{
			return new RefineryAgent(unit);
		}
		else
		{
			//Default structure agent
			return new StructureAgent(unit);
		}
	}
	else
	{
#if DISABLE_UNIT_AI == 0
		if (isOfType(unit, UnitTypes::Protoss_Zealot))
		{
			return new ZealotAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Dragoon))
		{
			return new DragoonAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Reaver))
		{
			return new ReaverAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Observer))
		{
			return new ObserverAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Dark_Templar))
		{
			return new DarkTemplarAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Scout))
		{
			return new ScoutAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Shuttle))
		{
			return new TransportAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Corsair))
		{
			return new CorsairAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Carrier))
		{
			return new CarrierAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_High_Templar))
		{
			return new HighTemplarAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Protoss_Arbiter))
		{
			return new ArbiterAgent(unit);
		}
		else
		{
			//Default unit agent
			return new UnitAgent(unit);
		}
#else
		return new UnitAgent(unit);
#endif
	}
	return NULL;
}
Ejemplo n.º 10
0
BaseAgent* AgentFactory::createTerranAgent(Unit* unit)
{
	if (unit->getType().isWorker())
	{
		return new WorkerAgent(unit);
	}
	else if (unit->getType().isBuilding())
	{
		//Add agents for special buildings here
		if (isOfType(unit, UnitTypes::Terran_Command_Center))
		{
			// Since there is no easy(and performance efficient) way 
			// to get the command centers we might as well just hook 
			// the fetch up here. (Add it to the list)
			TerranStrategy::CommandCenters.push_back( unit );
			return new CommandCenterAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Comsat_Station))
		{
			TerranStrategy::ComsatStations.push_back( unit );
			return new ComsatAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Refinery))
		{
			return new RefineryAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Bunker))
		{
			//Make sure we set the squad id to the bunker, so we
			//can remove the squad if the bunker is destroyed.
			int squadID = Commander::getInstance()->addBunkerSquad();
			BaseAgent* a = new StructureAgent(unit);
			a->setSquadID(squadID);
			return a;
		}
		else
		{
			//Default structure agent
			return new StructureAgent(unit);
		}
	}
	else
	{
#if DISABLE_UNIT_AI == 0
		if (isOfType(unit, UnitTypes::Terran_Siege_Tank_Tank_Mode))
		{
			return new SiegeTankAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Siege_Tank_Siege_Mode))
		{
			return new SiegeTankAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Marine))
		{
			return new MarineAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Firebat))
		{
			return new FirebatAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Medic))
		{
			return new MedicAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Vulture))
		{
			return new VultureAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Science_Vessel))
		{
			return new ScienceVesselAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Battlecruiser))
		{
			return new BattlecruiserAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Wraith))
		{
			return new WraithAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Ghost))
		{
			return new GhostAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Goliath))
		{
			return new GoliathAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Valkyrie))
		{
			return new ValkyrieAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Dropship))
		{
			return new TransportAgent(unit);
		}
		else
		{
			//Default unit agent
			return new UnitAgent(unit);
		}
#else
		return new UnitAgent(unit);
#endif
	}
	return NULL;
}
Ejemplo n.º 11
0
/*!
 * \internal
 */
THREEQuaternion *THREEQuaternion::getAsTHREEQuaternion(QJSValue value) {
    if (!isOfType(value, "QtThreeJSAccel::THREEQuaternion"))
        return 0;

    return static_cast<THREEQuaternion *>(value.toQObject());
}
Ejemplo n.º 12
0
BaseAgent* AgentFactory::createTerranAgent(Unit unit)
{
	if (unit->getType().isWorker())
	{
		return new WorkerAgent(unit);
	}
	else if (unit->getType().isBuilding())
	{
		//Add agents for special buildings here
		if (isOfType(unit, UnitTypes::Terran_Command_Center))
		{
			return new CommandCenterAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Comsat_Station))
		{
			return new ComsatAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Refinery))
		{
			return new RefineryAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Bunker))
		{
			//Make sure we set the squad id to the bunker, so we
			//can remove the squad if the bunker is destroyed.
			int squadID = Commander::getInstance()->addBunkerSquad();
			BaseAgent* a = new StructureAgent(unit);
			a->setSquadID(squadID);
			return a;
		}
		else
		{
			//Default structure agent
			return new StructureAgent(unit);
		}
	}
	else
	{
		if (isOfType(unit, UnitTypes::Terran_Siege_Tank_Tank_Mode))
		{
			return new SiegeTankAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Siege_Tank_Siege_Mode))
		{
			return new SiegeTankAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Marine))
		{
			return new MarineAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Firebat))
		{
			return new FirebatAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Medic))
		{
			return new MedicAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Vulture))
		{
			return new VultureAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Science_Vessel))
		{
			return new ScienceVesselAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Battlecruiser))
		{
			return new BattlecruiserAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Wraith))
		{
			return new WraithAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Ghost))
		{
			return new GhostAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Goliath))
		{
			return new UnitAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Valkyrie))
		{
			return new UnitAgent(unit);
		}
		else if (isOfType(unit, UnitTypes::Terran_Dropship))
		{
			return new TransportAgent(unit);
		}
		else
		{
			//Default unit agent
			return new UnitAgent(unit);
		}
	}
	return NULL;
}
Ejemplo n.º 13
0
void StructureAgent::computeActions()
{
	if (isAlive())
	{
		if (!unit->isIdle())
		{
			return;
		}

		if (UpgradesPlanner::getInstance()->checkUpgrade(this))
		{
			return;
		}

		if (BuildPlanner::isTerran())
		{
			//Check addons here
			if (isOfType(UnitTypes::Terran_Science_Facility))
			{
				if (unit->getAddon() == NULL)
				{
					unit->buildAddon(UnitTypes::Terran_Physics_Lab);
				}
			}
			if (isOfType(UnitTypes::Terran_Starport))
			{
				if (unit->getAddon() == NULL)
				{
					unit->buildAddon(UnitTypes::Terran_Control_Tower);
				}
			}
			if (isOfType(UnitTypes::Terran_Starport))
			{
				if (unit->getAddon() == NULL)
				{
					unit->buildAddon(UnitTypes::Terran_Control_Tower);
				}
			}
			if (isOfType(UnitTypes::Terran_Factory))
			{
				if (unit->getAddon() == NULL)
				{
					unit->buildAddon(UnitTypes::Terran_Machine_Shop);
				}
			}

			
			//scanner sweep on potential enemy locations(expansion sites) when having 200 energy
			if(isOfType(UnitTypes::Terran_Comsat_Station))
			{
				if(unit->getEnergy() == 200)
				{
					Broodwar->printf("200 energy reached for a comsat station, scanning with it...");
					vector<TilePosition> expSites = MalRilTilData::expansionPositions; //get expansion locations
					static int expSiteNr = 0;
					TilePosition scanPos = expSites.at(expSiteNr-- % expSites.size()); //next expansion site to scan
					
					//check for every unit if its in range of scan
					vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
					int scanRadius = 12 * 32; //in pixels (tank range = 12)
					for(int j = 0; j < (int)agents.size(); j++)
					{
						if(agents.at(j)->getUnit()->exists())
						{
							int dist = agents.at(j)->getUnit()->getDistance(Position(scanPos)); //distance(in pixels) between unit and scan position
							
							if(dist < scanRadius) //unit is within scanning radius, check next site
							{
								Broodwar->printf("Owned unit within scanning radius, checking next site...");
								scanPos = expSites.at(expSiteNr-- % expSites.size()); //get next expansion site
							}
						}
					}
					unit->useTech(TechTypes::Scanner_Sweep, Position(scanPos));
					Broodwar->printf("Scan used at: %d, %d", scanPos.x(), scanPos.y());
				}
			}

			/*If Comsat Station, check if we need to scan for enemy bases
			if (isOfType(UnitTypes::Terran_Comsat_Station))
			{
				TilePosition p = getNextScanLocation();
				if (p.x() != -1)
				{
					if (unit->getEnergy() >= 50)
					{
						//Broodwar->printf("Scanning (%d,%d)", p.x(), p.y());
						if (unit->useTech(TechTypes::Scanner_Sweep, Position(p)))
						{
							hasScanned.push_back(p);
							return;
						}
					}
				}
			}*/


			
		}

		if (!unit->isBeingConstructed() && unit->isIdle() && getUnit()->getType().canProduce())
		{
			//Iterate through all unit types
			for(set<UnitType>::iterator i=UnitTypes::allUnitTypes().begin();i!=UnitTypes::allUnitTypes().end();i++)
			{
				//Check if we can (and need) to build the unit
				if (canBuildUnit(*i))
				{
					//Build it!
					unit->train(*i);
				}
			}
		}
	}
}