Beispiel #1
0
/**
**  Research upgrade.
**
**  @return true when finished.
*/
/* virtual */ void COrder_Research::Execute(CUnit &unit)
{
	const CUpgrade &upgrade = this->GetUpgrade();
	const CUnitType &type = *unit.Type;


	//Wyrmgus start
//	UnitShowAnimation(unit, type.Animations->Research ? type.Animations->Research : type.Animations->Still);
	UnitShowAnimation(unit, unit.GetAnimations()->Research ? unit.GetAnimations()->Research : unit.GetAnimations()->Still);
	//Wyrmgus end
	if (unit.Wait) {
		unit.Wait--;
		return ;
	}
#if 0
	if (unit.Anim.Unbreakable) {
		return ;
	}
#endif
	//Wyrmgus start
//	CPlayer &player = *unit.Player;
	CPlayer &player = Players[this->Player];
//	player.UpgradeTimers.Upgrades[upgrade.ID] += std::max(1, player.SpeedResearch / SPEEDUP_FACTOR);
	player.UpgradeTimers.Upgrades[upgrade.ID] += std::max(1, (player.SpeedResearch + unit.Variable[TIMEEFFICIENCYBONUS_INDEX].Value + unit.Variable[RESEARCHSPEEDBONUS_INDEX].Value) / SPEEDUP_FACTOR);
	//Wyrmgus end
	if (player.UpgradeTimers.Upgrades[upgrade.ID] >= upgrade.Costs[TimeCost]) {
		if (upgrade.Name.empty()) {
			//Wyrmgus start
//			player.Notify(NotifyGreen, unit.tilePos, _("%s: research complete"), type.Name.c_str());
			player.Notify(NotifyGreen, unit.tilePos, unit.MapLayer->ID, _("%s: research complete"), type.GetDefaultName(player).c_str());
			//Wyrmgus end
		} else {
			player.Notify(NotifyGreen, unit.tilePos, unit.MapLayer->ID, _("%s: research complete"), upgrade.Name.c_str());
		}
		if (&player == ThisPlayer) {
			//Wyrmgus start
//			CSound *sound = GameSounds.ResearchComplete[player.Race].Sound;
			CSound *sound = GameSounds.ResearchComplete[unit.Player->Race].Sound;
			//Wyrmgus end

			if (sound) {
				PlayGameSound(sound, MaxSampleVolume);
			}
		}
		if (player.AiEnabled) {
			AiResearchComplete(unit, &upgrade);
		}
		UpgradeAcquire(player, &upgrade);
		this->Finished = true;
		return ;
	}
	unit.Wait = CYCLES_PER_SECOND / 6;
}
/**
**  Research upgrade.
**
**  @return true when finished.
*/
/* virtual */ void COrder_Research::Execute(CUnit &unit)
{
	const CUpgrade &upgrade = this->GetUpgrade();
	const CUnitType &type = *unit.Type;


	UnitShowAnimation(unit, type.Animations->Research ? type.Animations->Research : type.Animations->Still);
	if (unit.Wait) {
		unit.Wait--;
		return ;
	}
#if 0
	if (unit.Anim.Unbreakable) {
		return ;
	}
#endif
	CPlayer &player = *unit.Player;
	player.UpgradeTimers.Upgrades[upgrade.ID] += std::max(1, player.SpeedResearch / SPEEDUP_FACTOR);
	if (player.UpgradeTimers.Upgrades[upgrade.ID] >= upgrade.Costs[TimeCost]) {
		if (upgrade.Name.empty()) {
			player.Notify(NotifyGreen, unit.tilePos, _("%s: research complete"), type.Name.c_str());
		} else {
			player.Notify(NotifyGreen, unit.tilePos, _("%s: research complete"), upgrade.Name.c_str());
		}
		if (&player == ThisPlayer) {
			CSound *sound = GameSounds.ResearchComplete[player.Race].Sound;

			if (sound) {
				PlayGameSound(sound, MaxSampleVolume);
			}
		}
		if (player.AiEnabled) {
			AiResearchComplete(unit, &upgrade);
		}
		UpgradeAcquire(player, &upgrade);
		this->Finished = true;
		return ;
	}
	unit.Wait = CYCLES_PER_SECOND / 6;
}
/**
**	Unit researches!
**
**	@param unit	Pointer of researching unit.
*/
global void HandleActionResearch(Unit* unit)
{
    const Upgrade* upgrade;

    if( !unit->SubAction ) {		// first entry
	upgrade=unit->Data.Research.Upgrade=unit->Orders[0].Arg1;
#if 0
	// FIXME: I want to support both, but with network we need this check
	//	  but if want combined upgrades this is worse

	//
	//	Check if an other building has already started?
	//
	if( unit->Player->UpgradeTimers.Upgrades[upgrade-Upgrades] ) {
	    DebugLevel0Fn("Two researches running\n");
	    PlayerAddCosts(unit->Player,upgrade->Costs);

	    unit->Reset=unit->Wait=1;
	    unit->Orders[0].Action=UnitActionStill;
	    unit->SubAction=0;
	    if( IsOnlySelected(unit) ) {
		MustRedraw|=RedrawInfoPanel;
	    }
	    return;
	}
#endif
	unit->SubAction=1;
    } else {
	upgrade=unit->Data.Research.Upgrade;
    }

    unit->Player->UpgradeTimers.Upgrades[upgrade-Upgrades]+=SpeedResearch;
    if( unit->Player->UpgradeTimers.Upgrades[upgrade-Upgrades]
		>=upgrade->Costs[TimeCost] ) {

	NotifyPlayer(unit->Player,NotifyGreen,unit->X,unit->Y,
		"%s: complete",unit->Type->Name);
	if( unit->Player->Ai ) {
	    AiResearchComplete(unit,upgrade);
	}
        UpgradeAcquire(unit->Player,upgrade);

	unit->Reset=unit->Wait=1;
	unit->Orders[0].Action=UnitActionStill;
	unit->SubAction=0;

	// Upgrade can change all
	UpdateButtonPanel();
	MustRedraw|=RedrawPanels;

	return;
    }

    if( IsOnlySelected(unit) ) {
	MustRedraw|=RedrawInfoPanel;
    }

    unit->Reset=1;
    unit->Wait=CYCLES_PER_SECOND/6;

    // FIXME: should be animations here?
}