Ticket #1163: 1163.5.diff

File 1163.5.diff, 2.9 KB (added by trompetin17, 9 years ago)
  • source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    4848#include "simulation2/components/ICmpSelectable.h"
    4949#include "simulation2/components/ICmpTemplateManager.h"
    5050#include "simulation2/components/ICmpVisual.h"
     51#include "simulation2/components/ICmpObstruction.h"
    5152#include "simulation2/helpers/Selection.h"
    5253#include "ps/XML/XMLWriter.h"
    5354
     
    6162    }
    6263}
    6364
     65// Helpers for object constraints
     66bool CanPlaceObjectEntityHelper(entity_id_t ent)
     67{
     68    CmpPtr<ICmpObstruction> cmpObstruction(*g_Game->GetSimulation2(), ent);
     69    if (cmpObstruction)
     70    {
     71        ICmpObstruction::EFoundationCheck result = cmpObstruction->CheckFoundation("default");
     72        if (result != ICmpObstruction::FOUNDATION_CHECK_SUCCESS)
     73            return false;
     74    }
     75    return true;
     76}
     77
     78void CheckObstructionAndUpdateVisual(entity_id_t id)
     79{
     80    // Check build Constraint
     81    CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), id);
     82    if (cmpVisual)
     83    {
     84        if (!CanPlaceObjectEntityHelper(id))
     85            cmpVisual->SetShadingColour(fixed::FromDouble(1.4), fixed::FromDouble(0.4), fixed::FromDouble(0.4), fixed::FromDouble(1));
     86        else
     87            cmpVisual->SetShadingColour(fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1));
     88    }
     89}
     90
    6491QUERYHANDLER(GetObjectsList)
    6592{
    6693    std::vector<sObjectsListItem> objects;
     
    473500            posFinal = posFixed + dir;
    474501        }
    475502        cmpPosition->JumpTo(posFinal.X, posFinal.Z);
     503
     504        // Check build Constraint
     505        CheckObstructionAndUpdateVisual(id);
    476506    }
    477507}
    478508
     
    543573        CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), g_PreviewEntityID);
    544574        if (cmpOwnership)
    545575            cmpOwnership->SetOwner((player_id_t)msg->settings->player);
     576
     577        // Check build Constraint
     578        CheckObstructionAndUpdateVisual(g_PreviewEntityID);
    546579    }
    547580}
    548581
     
    599632        if (cmpVisual)
    600633        {
    601634            cmpVisual->SetActorSeed(m_ActorSeed);
     635            CheckObstructionAndUpdateVisual(m_EntityID);
    602636            // TODO: variation/selection strings
    603637        }
    604638    }
     
    736770        ObjectPositionMap::iterator it;
    737771        for (it = map.begin(); it != map.end(); ++it)
    738772        {
    739             CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)it->first);
     773            entity_id_t id = (entity_id_t)it->first;
     774            CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id);
    740775            if (!cmpPosition)
    741776                return;
    742777
     
    743778            // Set 2D position, ignoring height
    744779            CVector3D pos = it->second;
    745780            cmpPosition->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
     781
     782            // Check build Constraint
     783            CheckObstructionAndUpdateVisual(id);
    746784        }
    747785    }