Ejemplo n.º 1
0
MapArea AdapterEx::AdaptPositionForBuilding(EntityClassType p_buildingType)
{
    /*
    Position Adaptation Algorithm Outline:
    Use IM system to decide the best place for building
    - 1st Pass using Ground Control Map: The area with the highest control with regard to the player is selected for building
    - 2nd Pass using Occupance Data Map: Select the nearest available place to the center of the control to build in
    - Notes:
    1. The city shape will be spiral, and may not be the optimal build shape
    2. Building in a circle requires to choose the best place on the circle edge to build:
    1. Take into consideration the visibility and coverability of the position to build in
    2. The direction of growth should be taken into consideration, and the base main buildings should be well covered
    3. Critical buildings should be built in the back
    */
    Vector2    mapeSize = g_Game->Map()->Size();
    OccupanceDataIM    *pBuildingIM = (OccupanceDataIM*)g_IMSysMgr.GetIM(IM_BuildingData);
    GameType    *pGameType;
    unsigned    searchRadius;
    Vector2    colonyCenter;
    SpiralSearchData    searchData;

    pGameType = g_Game->GetEntityType(p_buildingType);
    assert(pGameType);

    // Append building width with padding of free space to achieve building spacing
    searchData.BuildingWidth = pGameType->Attr(ECATTR_Width) + (m_buildingSpacing * 2);
    searchData.BuildingHeight = pGameType->Attr(ECATTR_Height) + (m_buildingSpacing * 2);
    searchData.CandidateBuildPos = Vector2::Null();

    // This means to search all the map if the map is a square
    // Else if the map is a rectangle, we take the square part of it
    searchRadius = (int)((float)min(mapeSize.X, mapeSize.Y) / 2.0);

    colonyCenter = GetBotColonyCenter();
    pBuildingIM->SpiralMove(colonyCenter, searchRadius, BuildPositionSearchPredicate, &searchData);

    if (searchData.CandidateBuildPos == Vector2::Null())
    {
        return MapArea::Null();
    }
    else
    {
        // Shift the build position so that the building will be padded by a space
        searchData.CandidateBuildPos.X += m_buildingSpacing;
        searchData.CandidateBuildPos.Y += m_buildingSpacing;

        return MapArea(
            searchData.CandidateBuildPos,
            pGameType->Attr(ECATTR_Width),
            pGameType->Attr(ECATTR_Height));
    }
}
//----------------------------------------------------------------------------------------------
void ResourceDescription::RemoveEntity(GameEntity *p_entity)
{
    EntityClassType typeId = p_entity->Type();
    GameType* pType = g_Game->GetEntityType(typeId);

    if (!pType)
        return;

    if(pType && pType->Attr(ECATTR_IsPrimaryResource))
    {
        --m_numberOfPrimary;
    }
    else if (pType->Attr(ECATTR_IsSecondaryResource))
    {
        --m_numberOfSecondary;
    }
}
void BuildingDescription::AddEntity(GameEntity *p_entity)
{
    EntityClassType typeId;
    GameType *pType;

    _ASSERTE(p_entity);

    typeId = p_entity->Type();
    pType = g_Game->GetEntityType(typeId);
    _ASSERTE(pType);

    if (pType->Attr(ECATTR_IsBuilding))
    {
        ++m_numberOfBuildings;
        if (pType->Attr(ECATTR_IsCritical))
            ++m_numberOfCriticalBuildings;
    }
}
Ejemplo n.º 4
0
//----------------------------------------------------------------------------------------------
void TrainAction::InitializePostConditions()
{
    vector<Expression*> m_terms;
    EntityClassType entityTypeId = (EntityClassType)_params[PARAM_EntityClassId];
    GameType *pGameType = g_Game->GetEntityType(entityTypeId);

    if (!pGameType->Attr(ECATTR_IsCowrad))
    {
        m_terms.push_back(new PlayerAttributeExist(PLAYER_Self, PATTR_AlliedUnitsTotalHP, g_Game->GetEntityType(entityTypeId)->Attr(ECATTR_MaxHp)));
        m_terms.push_back(new PlayerAttributeExist(PLAYER_Self, PATTR_AlliedUnitsTotalDamage, g_Game->GetEntityType(entityTypeId)->Attr(ECATTR_Attack)));
    }
    
    m_terms.push_back(new EntityClassExist(PLAYER_Self, entityTypeId, 1));
    _postCondition = new And(m_terms);
}