예제 #1
0
void UnitBase::destroy() {

	setTarget(NULL);
	currentGameMap->removeObjectFromMap(getObjectID());	//no map point will reference now
	currentGame->getObjectManager().removeObject(objectID);

	currentGame->getHouse(originalHouseID)->decrementUnits(itemID);

	unitList.remove(this);

    if(isVisible()) {
        if(currentGame->randomGen.rand(1,100) <= getInfSpawnProp()) {
            UnitBase* pNewUnit = currentGame->getHouse(originalHouseID)->createUnit(Unit_Soldier);
            pNewUnit->setHealth(pNewUnit->getMaxHealth()/2);
            pNewUnit->deploy(location);

            if(owner->getHouseID() != originalHouseID) {
                // deviation is inherited
                pNewUnit->owner = owner;
                pNewUnit->graphic = pGFXManager->getObjPic(pNewUnit->graphicID,owner->getHouseID());
                pNewUnit->deviationTimer = deviationTimer;
            }
        }
    }

	delete this;
}
예제 #2
0
void Tile::triggerSpecialBloom(House* pTrigger) {
    if(isSpecialBloom()) {
        setType(Terrain_Sand);

        switch(currentGame->randomGen.rand(0,3)) {
        case 0: {
            // the player gets an randomly choosen amount of credits between 150 and 400
            pTrigger->addCredits(currentGame->randomGen.rand(150, 400),false);
        }
        break;

        case 1: {
            // The house gets a Trike for free. It spawns beside the special bloom.
            UnitBase* pNewUnit = pTrigger->createUnit(Unit_Trike);
            if(pNewUnit != NULL) {
                Coord spot = currentGameMap->findDeploySpot(pNewUnit, location);
                pNewUnit->deploy(spot);
            }
        }
        break;

        case 2: {
            // One of the AI players on the map (one that has at least one unit) gets a Trike for free. It spawns beside the special bloom.
            int numCandidates = 0;
            for(int i=0; i<NUM_HOUSES; i++) {
                House* pHouse = currentGame->getHouse(i);
                if(pHouse != NULL && pHouse->getTeam() != pTrigger->getTeam() && pHouse->getNumUnits() > 0) {
                    numCandidates++;
                }
            }

            if(numCandidates == 0) {
                break;
            }

            House* pEnemyHouse = NULL;
            for(int i=0; i<NUM_HOUSES; i++) {
                House* pHouse = currentGame->getHouse(i);
                if(pHouse != NULL && pHouse->getTeam() != pTrigger->getTeam() && pHouse->getNumUnits() > 0) {
                    numCandidates--;
                    if(numCandidates == 0) {
                        pEnemyHouse = pHouse;
                        break;
                    }
                }
            }

            UnitBase* pNewUnit = pEnemyHouse->createUnit(Unit_Trike);
            if(pNewUnit != NULL) {
                Coord spot = currentGameMap->findDeploySpot(pNewUnit, location);
                pNewUnit->deploy(spot);
            }

        }
        break;

        case 3:
        default: {
            // One of the AI players on the map (one that has at least one unit) gets an Infantry unit (3 Soldiers) for free. The spawn beside the special bloom.
            int numCandidates = 0;
            for(int i=0; i<NUM_HOUSES; i++) {
                House* pHouse = currentGame->getHouse(i);
                if(pHouse != NULL && pHouse->getTeam() != pTrigger->getTeam() && pHouse->getNumUnits() > 0) {
                    numCandidates++;
                }
            }

            if(numCandidates == 0) {
                break;
            }

            House* pEnemyHouse = NULL;
            for(int i=0; i<NUM_HOUSES; i++) {
                House* pHouse = currentGame->getHouse(i);
                if(pHouse != NULL && pHouse->getTeam() != pTrigger->getTeam() && pHouse->getNumUnits() > 0) {
                    numCandidates--;
                    if(numCandidates == 0) {
                        pEnemyHouse = pHouse;
                        break;
                    }
                }
            }

            for(int i=0; i<3; i++) {
                UnitBase* pNewUnit = pEnemyHouse->createUnit(Unit_Soldier);
                if(pNewUnit != NULL) {
                    Coord spot = currentGameMap->findDeploySpot(pNewUnit, location);
                    pNewUnit->deploy(spot);
                }
            }
        }
        break;
        }
    }
}