예제 #1
0
void UIAssetController::onButtonClick(BasicButton* pSrc)
{
    // stop-command for units
    if(pSrc == m_pStopButton) {
        DoubleLinkedList<Unit*>* pUnitList = m_pUnitCommandDispatcher->getUnits();
        ListNode<Unit*>* node = pUnitList->headNode();
        while(node) {
            if(node->item->getMovingLogic())
                node->item->getMovingLogic()->clearTargets();
            node = node->next;
        }
        return;
    }

    if (pSrc->getId() == 666)
    {
        // launch nuke
        m_pSelector->setState(Selector::SELECTOR_NUKE);
        changeState(STATE_NUKE);
        return;
    }

    // build button
    // check for insufficient funds
    /*
    AssetDef* def = (AssetDef*)pSrc->getRandomObject();
    if(!def)
        def = DefManager::getInstance()->getAssetDef(pSrc->getId());
    */
    AssetDef* def = DefManager::getInstance()->getAssetDef(pSrc->getId());
    if(m_pCurrentPlayer->getOre() < def->constructionCostOre) {
        Console::error("Cannot build: not enough ore");
        return;
    }
    if(def->constructionRequires && !m_pCurrentPlayer->hasAsset(def->constructionRequires)) {
        Console::error("Cannot build: requirements not met");
        return;
    }
    // take the ore first to prefent the situation where there is no funds when placed
    m_CurrentBuildOreTaken = def->constructionCostOre;
    m_pCurrentPlayer->modifyOre(-m_CurrentBuildOreTaken);
    // start building
    m_pCurrentBuildAssetDef = def;
    m_pCurrentBuildButton = pSrc;
    changeState(STATE_BUILDING_PLACEMENT);
}
예제 #2
0
파일: Fog.cpp 프로젝트: underkround/mazerts
void Fog::update(float deltaT)
{
    m_UpdateCounter += deltaT;
    if(m_UpdateCounter < m_UpdateInterval)
        return;
    m_UpdateCounter = 0.0f;
    m_ChangeCounter++;

    // reset fog
    const unsigned short len = Terrain::getInstance()->getSize();
    for (unsigned short y = 0; y < len; y++)
    {
        memset(m_Fog[y], false, len * sizeof(bool));
    }

    // add units & buildings visibilities
    for (int asd = 0; asd < 2; asd++) { // 0 = units, 1 = buildings
        ListNode<Unit*>* lnu = NULL;
        ListNode<Building*>* lnb = NULL;
        if (asd == 0) {
            DoubleLinkedList<Unit*>* units = AssetCollection::getAllUnits();
            lnu = units->headNode();
        } else {
            DoubleLinkedList<Building*>* buildings = AssetCollection::getAllBuildings();
            lnb = buildings->headNode();
        }
        while (lnu || lnb)
        {
            IAsset* pAsset = NULL;
            if (lnu)
                pAsset = (IAsset*)lnu->item;
            else
                pAsset = (IAsset*)lnb->item;

            if (pAsset->getOwner() == getOwner()) {
                const unsigned short radius = (unsigned short) pAsset->getDef()->pDefRadar->range; // TODO: float? everywhere?
                const unsigned short centerx = pAsset->getCenterGridX();
                const unsigned short centery = pAsset->getCenterGridY();

                FOGMASK* fm = getFogMask(radius);
                if (centerx - radius >= 0 && centerx + radius < len)
                {
                    // totally inside map (horizontally)
                    short y = centery - radius;
                    unsigned short yoffset = 0;
                    unsigned short ycutoff = 0;
                    if (centery - radius < 0) yoffset = abs(centery - radius);
                    if (centery + radius >= len) ycutoff = abs(len - (centery + radius));

                    ListNode<Fog::FOGROW*>* row = fm->data.headNode();
                    while (row)
                    {
                        if (y >= centery - radius + yoffset)
                            memset(&m_Fog[y][centerx - radius + row->item->offset], true, row->item->amount);
                        ++y;
                        if (y >= centery + radius - ycutoff) break;
                        row = row->next;
                    }
                }
                else
                {
                    // partially over edge (horizontally)
                    unsigned short yoffset = 0;
                    unsigned short ycutoff = 0;

                    if (centery - radius < 0) yoffset = abs(centery - radius);
                    if (centery + radius >= len) ycutoff = abs(len - (centery + radius));

                    short y = centery - radius;
                    ListNode<Fog::FOGROW*>* row = fm->data.headNode();
                    while (row)
                    {
                        if (y >= centery - radius + yoffset) {
                            for (int x = max(row->item->offset + centerx - radius, 0); x < min(len, (unsigned short)(centerx - radius + row->item->offset + row->item->amount)); x++) {
                                m_Fog[y][x] = true;
                            }
                        }
                        ++y;
                        if (y >= centery + radius - ycutoff) break;
                        row = row->next;
                    }
                }
            }
            if (lnu)
                lnu = lnu->next;
            else if (lnb)
                lnb = lnb->next;
        }
    }
}
예제 #3
0
void UIAssetController::onPickRelease(const float frameTime)
{
    // ===== Pick button released

    D3DXMATRIX matProj, matView;
    D3DXVECTOR3 rayOrigin, rayDir;
    m_pDevice->GetTransform(D3DTS_PROJECTION, &matProj);
    m_pDevice->GetTransform(D3DTS_VIEW, &matView);
    MouseState::transformTo3D(matView, matProj, rayOrigin, rayDir);

    switch(m_SelectionState)
    {

    default:
    case IDLE:
    case CLICK:
        {
            break;
        }

    case DRAG:
        {
            clearSelection();
            Selector::SELECTION* selection = m_pSelector->buttonUp();
            if(!selection->assets.empty())
            {
                // check if selection is buildings or units
                DoubleLinkedList<UIAsset*> templist;

                ListNode<UIAsset*>* pNode = selection->assets.headNode();
                while(pNode)
                {
                    UIAsset* pAsset = pNode->item;
                    if (pAsset->getAsset()->getAssetType() == IAsset::UNIT && m_pCurrentPlayer == pAsset->getAsset()->getOwner())
                    {
                        if (m_SelectedAssetType != UNIT) {
                            templist.release();
                            m_pInstanceControlPanel->removeAllComponents();
                            m_pCurrentBuildQueue = 0;
                        }
                        m_SelectedAssetType = UNIT;
                        templist.pushHead(pAsset);
                        // show stop-button for friendly asset selection
                    }
                    else if ((m_SelectedAssetType == NONE || m_SelectedAssetType == ENEMY) && m_pCurrentPlayer == pAsset->getAsset()->getOwner() && pAsset->getAsset()->getAssetType() == IAsset::BUILDING)
                    {
                        if (m_SelectedAssetType != BUILDING) {
                            templist.release();
                            m_pInstanceControlPanel->removeAllComponents();
                            m_pCurrentBuildQueue = 0;
                        }
                        m_SelectedAssetType = BUILDING;
                        templist.pushHead(pAsset);
                    }
                    else if (m_SelectedAssetType == NONE && m_pCurrentPlayer != pAsset->getAsset()->getOwner())
                    {
                        m_SelectedAssetType = ENEMY;
                        templist.pushHead(pAsset);
                    }
                    pNode = pNode->next;
                }

                // add the selection to units under control
                pNode = templist.headNode();
                if(pNode)
                {
                    if (m_SelectedAssetType != ENEMY)
                        SoundManager::playSound(SOUND_YES, 0.1f, *(D3DXVECTOR3*)&pNode->item->GetMatrix()._41, false);

                    // show stop-button for friendly asset selection
                    if(m_pInstanceControlPanel->empty() && m_SelectedAssetType == UNIT) {
                        m_pInstanceControlPanel->addComponent(m_pStopButton);
                    }
                    // show build menu for factories
                    else if(m_SelectedAssetType == BUILDING && pNode->item) {
                        if(pNode->item->getAsset()->getDef()->isfactory) {
                            setupBuildQueue(pNode->item->getAsset());
                        } else if (pNode->item->getAsset()->getTypeTag() == BUILDING_TYPE_SILO) {
                            // show nuke
                            m_pInstanceControlPanel->removeAllComponents();
                            m_pInstanceControlPanel->addComponent(m_pNukeButton);
                            setNukeSilo((Building*)pNode->item->getAsset());
                        } else {
                            m_pInstanceControlPanel->removeAllComponents();
                            m_pCurrentBuildQueue = 0;
                            setNukeSilo(NULL);
                        }
                    }

                    while(pNode)
                    {
                        UIAsset* pAsset = pNode->item;
                        if(!pAsset->isSelected())
                        {
                            if (pAsset->getAsset()->getAssetType() == IAsset::UNIT && m_SelectedAssetType != ENEMY) // if you comment out the enemy check, you can move enemies
                                m_pUnitCommandDispatcher->addUnit((Unit*)pAsset->getAsset());
                            pAsset->setSelected(true);
                            m_SelectedUIAssets.pushHead(pAsset);
                        }
                        pNode = pNode->next;
                    }
                }
            }
            delete selection;
            break;
        }

    } // switch

    if(m_SelectedUIAssets.empty()) {
        if(!m_pInstanceControlPanel->getChildren()->empty()) {
            m_pInstanceControlPanel->removeAllComponents();
        }
    }

    m_SelectionState = IDLE;
    m_TempMouseX = 0;
    m_TempMouseY = 0;
}