Пример #1
0
void LairAgent::computeActions() {
	doResearch();

	if ((int)researchOrder.size() == 0) {
		doUpgrades();
	}

	int level = ((ZergCommander*)Commander::getInstance())->getLevel();
	if (level >= 5)
	{
		if (canUpgrade(UpgradeTypes::Ventral_Sacs))
			unit->upgrade(UpgradeTypes::Ventral_Sacs);		
		else if (canUpgrade(UpgradeTypes::Antennae))
			unit->upgrade(UpgradeTypes::Antennae);
		else if (canUpgrade(UpgradeTypes::Pneumatized_Carapace))
			unit->upgrade(UpgradeTypes::Pneumatized_Carapace);
		return;
	}


	//// upgrade to lair if level 5
	//int level = ((ZergCommander*)Commander::getInstance())->getLevel();
	//if (level >= 5 && unit->getType() != UnitTypes::Zerg_Lair)
	//{
	//	unit->upgrade(UpgradeTypes::Zer);
	//}

	// build drones
	ZergCommander* zc = ((ZergCommander*)Commander::getInstance());
	UnitType worker = Broodwar->self()->getRace().getWorker();
	while (zc->getWorkersNeeded() > 0 && canBuild(worker))
	{
		unit->train(worker);
		zc->setWorkersNeeded(zc->getWorkersNeeded()-1);
	}

	// build hydralisks
	UnitType hydralisk = UnitTypes::Zerg_Hydralisk;
	if (Commander::getInstance()->needUnit(hydralisk)) {
		if (canBuild(hydralisk)) {
			unit->train(hydralisk);
			return;
		}
	}

	// build zerglings
	UnitType zergling = UnitTypes::Zerg_Zergling;
	if (Commander::getInstance()->needUnit(zergling)) {
		if (canBuild(zergling)) {
			unit->train(zergling);
			return;
		}
	}
}
	void UpgradeManager::upgrade(Unit *unit, int upgradeId)
	{
		assert(upgradeId >= 0 && upgradeId < MAX_UPGRADE_TYPES);
		assert(unit != NULL);

		if (!canUpgrade(unit, upgradeId))
		{
			assert(!"UpgradeManager::upgrade - Upgrade called even though it cannot be done?");
			return;
		}

		int num = 0;
		Item *item;
		if(isCharacterUpgrade(upgradeId)) item = getUnitCharacterPartItem(unit, &num);
		else item = getUnitUpgradeItem(unit, &num);

		assert(item != NULL);

		if (item->getCount() > upgradeTypes[upgradeId].getCost())
		{
			item->setCount(item->getCount() - upgradeTypes[upgradeId].getCost());
		} else {
			Item *item = unit->removeItem(num);
			if (item != NULL)
			{
				delete item;
			} else {
				Logger::getInstance()->warning("Unit upgradepart item remove failed.");
				assert(!"Unit upgradepart item remove failed.");
			}
		}

		game->gameScripting->runOtherScript(upgradeTypes[upgradeId].getScript(), "upgrade", unit, VC3(0,0,0));
	}
Пример #3
0
void buy(unsigned *upgrade) {
	// Checks if you can buy the upgrade (call canUpgrade())
	// If you can, subtracts the cost from money, and gets the upgrade
	// Otherwise, prints out a warning, and returns

	if (*upgrade >= MAX_LEVEL) {
		printf("\n--- Already at maximum level ---\n");

		getFirstCharOfLine();
		return;
	}
	
	int price = canUpgrade(upgrade);

	if (price != -1){
		doves = doves - price;
		(*upgrade)++;

		printf("\n--- Successfully purchaced upgrade for %d doves! ---\n", price);

		getFirstCharOfLine();

	} else{ // cannont affored upgrade (-1)

		printf("\n--- Cannot afford upgrade! ---\n");

		getFirstCharOfLine();

	}
}
Пример #4
0
void EvolutionChamberAgent::computeActions() {
	if (canUpgrade(UpgradeTypes::Zerg_Melee_Attacks))
	{
		unit->upgrade(UpgradeTypes::Zerg_Melee_Attacks);
		//return;
	}
	
	int level = ((ZergCommander*)Commander::getInstance())->getLevel();
	if (level >= 5)
	{
		if (canUpgrade(UpgradeTypes::Zerg_Carapace))
			unit->upgrade(UpgradeTypes::Zerg_Carapace);

		if (canUpgrade(UpgradeTypes::Zerg_Missile_Attacks))
			unit->upgrade(UpgradeTypes::Zerg_Missile_Attacks);
	}
}
Пример #5
0
bool Upgrader::checkUpgrade(BaseAgent* agent)
{
	if (agent->isAlive() && agent->getUnit()->isIdle())
	{
		Unit* unit = agent->getUnit();

		//Check techs
		for (int i = 0; i < (int)techs.size(); i++)
		{
			TechType type = techs.at(i);
			if (Broodwar->self()->hasResearched(type))
			{
				techs.erase(techs.begin() + i);
				return true;
			}
			if (canResearch(type, unit))
			{
				unit->research(type);
				return true;
			}
		}

		//Check upgrades
		for (int i = 0; i < (int)upgrades.size(); i++)
		{
			UpgradeType type = upgrades.at(i);
			if (canUpgrade(type, unit))
			{
				if (unit->upgrade(type))
				{
					upgrades.erase(upgrades.begin() + i);
					return true;
				}
			}
		}
	}

	return false;
}
Пример #6
0
void MenuPowers::logic() {
	for (unsigned i=0; i<power_cell_unlocked.size(); i++) {
		if (static_cast<unsigned>(power_cell_unlocked[i].id) < powers->powers.size() && powers->powers[power_cell_unlocked[i].id].passive) {
			bool unlocked_power = std::find(stats->powers_list.begin(), stats->powers_list.end(), power_cell_unlocked[i].id) != stats->powers_list.end();
			std::vector<int>::iterator it = std::find(stats->powers_passive.begin(), stats->powers_passive.end(), power_cell_unlocked[i].id);

			if (it != stats->powers_passive.end()) {
				if (!baseRequirementsMet(power_cell_unlocked[i].id) && power_cell_unlocked[i].passive_on) {
					stats->powers_passive.erase(it);
					stats->effects.removeEffectPassive(power_cell_unlocked[i].id);
					power_cell[i].passive_on = false;
					stats->refresh_stats = true;
				}
			}
			else if (((baseRequirementsMet(power_cell_unlocked[i].id) && !power_cell_unlocked[i].requires_point) || unlocked_power) && !power_cell_unlocked[i].passive_on) {
				stats->powers_passive.push_back(power_cell_unlocked[i].id);
				power_cell_unlocked[i].passive_on = true;
				// for passives without special triggers, we need to trigger them here
				if (stats->effects.triggered_others)
					powers->activateSinglePassive(stats, power_cell_unlocked[i].id);
			}
		}
	}

	for (unsigned i=0; i<power_cell.size(); i++) {
		//upgrade buttons logic
		if (upgradeButtons[i] != NULL) {
			upgradeButtons[i]->enabled = false;
			// enable button only if current level is unlocked and next level can be unlocked
			if (canUpgrade(static_cast<short>(i))) {
				upgradeButtons[i]->enabled = true;
			}
			if ((!tab_control || power_cell[i].tab == tab_control->getActiveTab()) && upgradeButtons[i]->checkClick()) {
				upgradePower(static_cast<short>(i));
			}
		}
	}

	points_left = static_cast<short>((stats->level * stats->power_points_per_level) - getPointsUsed());
	if (points_left > 0) {
		newPowerNotification = true;
	}

	if (!visible) return;

	tablist.logic();

	if (closeButton->checkClick()) {
		visible = false;
		snd->play(sfx_close);
	}

	if (tab_control) {
		// make shure keyboard navigation leads us to correct tab
		for (unsigned int i = 0; i < slots.size(); i++) {
			if (slots[i] && slots[i]->in_focus)
				tab_control->setActiveTab(power_cell[i].tab);
		}

		tab_control->logic();
	}
}