Ticket #1163: 1163.4.diff

File 1163.4.diff, 3.0 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        //use default passClasName.
     72        ICmpObstruction::EFoundationCheck result = cmpObstruction->CheckFoundation("default");
     73        if (result != ICmpObstruction::FOUNDATION_CHECK_SUCCESS)
     74            return false;
     75    }
     76    return true;
     77}
     78
     79void CheckObstructionAndUpdateVisual(entity_id_t id)
     80{
     81    //Check build Constraint
     82    CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), id);
     83    if (cmpVisual)
     84    {
     85        if (!CanPlaceObjectEntityHelper(id))
     86            cmpVisual->SetShadingColour(fixed::FromDouble(1.4), fixed::FromDouble(0.4), fixed::FromDouble(0.4), fixed::FromDouble(1));
     87        else
     88            cmpVisual->SetShadingColour(fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1));
     89    }
     90}
     91
    6492QUERYHANDLER(GetObjectsList)
    6593{
    6694    std::vector<sObjectsListItem> objects;
     
    473501            posFinal = posFixed + dir;
    474502        }
    475503        cmpPosition->JumpTo(posFinal.X, posFinal.Z);
     504
     505        //Check build Constraint
     506        CheckObstructionAndUpdateVisual(id);
    476507    }
    477508}
    478509
     
    543574        CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), g_PreviewEntityID);
    544575        if (cmpOwnership)
    545576            cmpOwnership->SetOwner((player_id_t)msg->settings->player);
     577
     578        //Check build Constraint
     579        CheckObstructionAndUpdateVisual(g_PreviewEntityID);
    546580    }
    547581}
    548582
     
    599633        if (cmpVisual)
    600634        {
    601635            cmpVisual->SetActorSeed(m_ActorSeed);
     636            CheckObstructionAndUpdateVisual(m_EntityID);
    602637            // TODO: variation/selection strings
    603638        }
    604639    }
     
    736771        ObjectPositionMap::iterator it;
    737772        for (it = map.begin(); it != map.end(); ++it)
    738773        {
    739             CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)it->first);
     774            entity_id_t id = (entity_id_t)it->first;
     775            CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id);
    740776            if (!cmpPosition)
    741777                return;
    742778
     
    743779            // Set 2D position, ignoring height
    744780            CVector3D pos = it->second;
    745781            cmpPosition->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
     782
     783            //Check build Constraint
     784            CheckObstructionAndUpdateVisual(id);
    746785        }
    747786    }