Exemplo n.º 1
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;
        }
    }
}