Пример #1
0
void Tile::setType(int newType) {
    type = newType;
    destroyedStructureTile = DestroyedStructure_None;

    if (type == Terrain_Spice) {
        spice = currentGame->randomGen.rand(RANDOMSPICEMIN, RANDOMSPICEMAX);
    } else if (type == Terrain_ThickSpice) {
        spice = currentGame->randomGen.rand(RANDOMTHICKSPICEMIN, RANDOMTHICKSPICEMAX);
    } else if (type == Terrain_Dunes) {
    } else {
        spice = 0;
        if (isRock()) {
            sandRegion = NONE;
            if (hasAnUndergroundUnit())	{
                ObjectBase* current;
                std::list<Uint32>::const_iterator iter;
                iter = assignedUndergroundUnitList.begin();

                do {
                    current = currentGame->getObjectManager().getObject(*iter);
                    ++iter;

                    if(current == NULL)
                        continue;

                    unassignUndergroundUnit(current->getObjectID());
                    current->destroy();
                } while(iter != assignedUndergroundUnitList.end());
            }

            if(type == Terrain_Mountain) {
                if(hasANonInfantryGroundObject()) {
                    ObjectBase* current;
                    std::list<Uint32>::const_iterator iter;
                    iter = assignedNonInfantryGroundObjectList.begin();

                    do {
                        current = currentGame->getObjectManager().getObject(*iter);
                        ++iter;

                        if(current == NULL)
                            continue;

                        unassignNonInfantryGroundObject(current->getObjectID());
                        current->destroy();
                    } while(iter != assignedNonInfantryGroundObjectList.end());
                }
            }
        }
    }

    for (int i=location.x; i <= location.x+3; i++) {
        for (int j=location.y; j <= location.y+3; j++) {
            if (currentGameMap->tileExists(i, j)) {
                currentGameMap->getTile(i, j)->clearTerrain();
            }
        }
    }
}
Пример #2
0
void UnitBase::handleAttackClick(int xPos, int yPos) {
	if(respondable) {
		if(currentGameMap->tileExists(xPos, yPos)) {
			if(currentGameMap->getTile(xPos,yPos)->hasAnObject()) {
				// attack unit/structure or move to structure
				ObjectBase* tempTarget = currentGameMap->getTile(xPos,yPos)->getObject();

				currentGame->getCommandManager().addCommand(Command(pLocalPlayer->getPlayerID(), CMD_UNIT_ATTACKOBJECT,objectID,tempTarget->getObjectID()));
			} else {
				// attack pos
				currentGame->getCommandManager().addCommand(Command(pLocalPlayer->getPlayerID(), CMD_UNIT_ATTACKPOS,objectID,(Uint32) xPos, (Uint32) yPos, (Uint32) true));
			}
		}
	}

}