void PlayerMenuUserInterface::playerSelected(U32 index) const
{
   // When we created the menu, names were not sorted, and item indices were assigned in "natural order".  Then
   // the menu items were sorted by name, and now the indices are now jumbled.  This bit here tries to get the
   // new, actual list index of an item given its original index.
   for(S32 i = 0; i < getMenuItemCount(); i++)
      if(getMenuItem(i)->getIndex() == (S32)index)
      {
         index = i;
         break;
      }

   GameType *gt = getGame()->getGameType();

   if(action == PlayerActionChangeTeam)
   {
      TeamMenuUserInterface *ui = getUIManager()->getUI<TeamMenuUserInterface>();
      ui->mNameToChange = getMenuItem(index)->getPrompt();

      getUIManager()->activate<TeamMenuUserInterface>();     // Show menu to let player select a new team
   }

   else if(gt)    // action == Kick
      gt->c2sKickPlayer(getMenuItem(index)->getPrompt());


   if(action != PlayerActionChangeTeam)      // Unless we need to move on to the change team screen...
      getUIManager()->reactivateGameUI();    // ...it's back to the game!
}
Esempio n. 2
0
bool NexusZone::collide(BfObject *hitObject)
{
    if(isGhost())
        return false;

    // From here on out, runs on server only

    if( ! (isShipType(hitObject->getObjectTypeNumber())) )
        return false;

    Ship *theShip = static_cast<Ship *>(hitObject);

    if(theShip->mHasExploded)                             // Ignore collisions with exploded ships
        return false;

    GameType *gameType = getGame()->getGameType();
    NexusGameType *nexusGameType = NULL;

    if(gameType && gameType->getGameTypeId() == NexusGame)
        nexusGameType = static_cast<NexusGameType *>(getGame()->getGameType());

    if(nexusGameType && nexusGameType->isNexusOpen())      // Is the nexus open?
        nexusGameType->shipTouchNexus(theShip, this);

    return false;
}
void InfluenceMap::RegisterGameObj(TID objId, PlayerType ownerId)
{
    if (m_registeredObjects.count(objId) == 0)
    {
        RegObjEntry *pNewObj = new RegObjEntry;
        GameEntity *pGameObj = nullptr;
        GameType *pObjType = nullptr;

        pNewObj->ObjId = objId;
        pNewObj->OwnerId = ownerId;
        pNewObj->Stamped = false;

        pGameObj = g_Game->GetPlayer(ownerId)->GetEntity(objId);
        _ASSERTE(pGameObj);
        pNewObj->LastPosition = Vector2(-1, -1);

        pObjType = g_Game->GetEntityType((EntityClassType)pGameObj->TypeId());
        _ASSERTE(pObjType);

        pNewObj->ObjWidth = pObjType->P(TP_Width) + pObjType->P(TP_BuildingExpansionIncrement);
        pNewObj->ObjHeight = pObjType->P(TP_Height);

        m_registeredObjects[objId] = pNewObj;
    }
}
Esempio n. 4
0
// Runs as we're exiting the menu
void GameParamUserInterface::onEscape()
{
   EditorUserInterface *ui = getUIManager()->getUI<EditorUserInterface>();

   string newFilename = getMenuItem(1)->getValue();

   bool filenameChanged = mLevelFilename != newFilename;
   if(filenameChanged)
      ui->setLevelFileName(newFilename);

   GameType *gameType = getUIManager()->getUI<EditorUserInterface>()->getLevel()->getGameType();

   const Vector<string> *keys = gameType->getGameParameterMenuKeys();

   for(S32 i = 0; i < keys->size(); i++)
   {
      MenuItemMap::iterator iter = mMenuItemMap.find(keys->get(i));

      MenuItem *menuItem = iter->second.get();
      gameType->saveMenuItem(menuItem, keys->get(i));
   }

   if(anythingChanged() || filenameChanged)
   {
      EditorUserInterface *ui = getUIManager()->getUI<EditorUserInterface>();
      // TODO -->Save undo state here!!!
      ui->validateLevel();
   }

   // Now back to our previously scheduled program...  (which will be the editor, of course)
   getUIManager()->reactivatePrevUI();
}
Esempio n. 5
0
void NexusFlagItem::dismount(DismountMode dismountMode)
{
    if(isGhost())      // Server only
        return;
    if(getDatabase() == NULL)  // must be in database, switching levels makes database NULL
        return;

    if(dismountMode == DISMOUNT_MOUNT_WAS_KILLED)
    {
        // Should getting shot up count as a flag drop event for statistics purposes?
        if(mMount && mMount->getClientInfo())
            mMount->getClientInfo()->getStatistics()->mFlagDrop += mFlagCount + 1;

        dropFlags(mFlagCount + 1);    // Drop at least one flag plus as many as the ship carries

        // Now delete the flag itself
        removeFromDatabase(false);
        deleteObject();
    }
    else
    {
        GameType *gameType = getGame()->getGameType();
        if(!gameType)        // Crashed here once, don't know why, so I added the check
            return;

        gameType->itemDropped(mMount, this, dismountMode); // Sends messages; no flags actually dropped here; server only method
        dropFlags(mFlagCount);                             // Only dropping the flags we're carrying, not the "extra" one that comes when we die
    }
}
Esempio n. 6
0
/**
 * @luafunc int LuaGameInfo::getNexusTimeLeft()
 *
 * @brief The number of seconds until the nexus opens or closes.
 *
 * @return The number of seconds until the Nexus opens or closes, or nil if this
 * is not a nexus game.  If this function returns 0, the Nexus will remain in its 
 * current state until the end of the game
 */
S32 LuaGameInfo::lua_getNexusTimeLeft(lua_State *L)
{
   GameType *gameType = mServerGame->getGameType();
   if(!gameType || gameType->getGameTypeId() != NexusGame)
      return returnNil(L);

   return returnInt(L, static_cast<NexusGameType *>(gameType)->getNexusTimeLeftMs() / 1000);
}
Esempio n. 7
0
/**
 * @luafunc bool LuaGameInfo::isNexusOpen()
 *
 * @brief Get whether the nexus is open
 *
 * @return `true` if the Nexus is open during a Nexus game.
 */
S32 LuaGameInfo::lua_isNexusOpen(lua_State *L)
{
   GameType *gameType = mServerGame->getGameType();
   if(!gameType || gameType->getGameTypeId() != NexusGame)
      return returnNil(L);

   return returnBool(L, static_cast<NexusGameType *>(gameType)->isNexusOpen());
}
Esempio n. 8
0
// Only used during level load process...  actually, used at all?  If so, should be combined with similar code in gameType
// Not used during normal game load... used by tests and lua_setGameTime()
void Game::setGameTime(F32 timeInMinutes)
{
   GameType *gt = getGameType();

   TNLAssert(gt, "Null gametype!");

   if(gt)
      gt->setGameTime(timeInMinutes * 60);
}
Esempio n. 9
0
void NexusZone::onAddedToGame(Game *theGame)
{
    Parent::onAddedToGame(theGame);

    if(!isGhost())
        setScopeAlways();    // Always visible!

    GameType *gameType = getGame()->getGameType();

    if(gameType && gameType->getGameTypeId() == NexusGame)
        static_cast<NexusGameType *>(gameType)->addNexus(this);
}
Esempio n. 10
0
/**
 * @luafunc bool NexusZone::isOpen()
 *
 * @return The current state of the Nexus. `true` for open, `false` for closed.
 *
 * @note Since all Nexus items open and close together, this method will return
 * the same value for all Nexus zones in a game at any given time.
 */
S32 NexusZone::lua_isOpen(lua_State *L)
{
    if(!mGame)
        return returnBool(L, false);

    GameType *gameType = mGame->getGameType();

    if(gameType->getGameTypeId() == NexusGame)
        return returnBool(L, static_cast<NexusGameType *>(gameType)->isNexusOpen());
    else
        return returnBool(L, false);     // If not a Nexus game, Nexus will never be open
}
Esempio n. 11
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));
    }
}
Esempio n. 12
0
void NexusZone::render() const
{
#ifndef ZAP_DEDICATED
    GameType *gameType = getGame() ? getGame()->getGameType() : NULL;
    NexusGameType *nexusGameType = NULL;

    if(gameType && gameType->getGameTypeId() == NexusGame)
        nexusGameType = static_cast<NexusGameType *>(gameType);

    bool isOpen = nexusGameType && nexusGameType->isNexusOpen();
    F32 glowFraction = gameType ? gameType->mZoneGlowTimer.getFraction() : 0;

    GameObjectRender::renderNexus(getOutline(), getFill(), getCentroid(), getLabelAngle(), isOpen, glowFraction);
#endif
}
Esempio n. 13
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);
}
Esempio n. 14
0
/**
 * @luafunc NexusZone::setClosedTime(int seconds)
 *
 * @brief Set the time (in seconds) that the Nexus will remain closed.
 *
 * @descr Pass 0 if the Nexus should never open, causing the Nexus to remain
 * closed permanently. Passing a negative time will generate an error.
 *
 * @param seconds Time in seconds that the Nexus should remain closed.
 *
 * @note Since all Nexus items open and close together, this method will affect
 * all Nexus items in a game.
 *
 * Also note that in a level file, closing times are specified in fractions of
 * minutes, whereas this method works with seconds.
 */
S32 NexusZone::lua_setClosedTime(lua_State *L)
{
    checkArgList(L, functionArgs, "NexusZone", "setCloseTime");

    if(!mGame)
        return 0;

    GameType *gameType = mGame->getGameType();

    if(gameType->getGameTypeId() != NexusGame)       // Do nothing if this is not a Nexus game
        return 0;

    static_cast<NexusGameType *>(gameType)->setNewClosedTime(getInt(L, 1));

    return 0;
}
//----------------------------------------------------------------------------------------------
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;
    }
}
Esempio n. 17
0
void GameMenuUserInterface::onActivate()
{
   Parent::onActivate();
   menuItems.clear();
   menuItems.push_back(MenuItem("OPTIONS",1));
   menuItems.push_back(MenuItem("INSTRUCTIONS",2));
   GameType *theGameType = gClientGame->getGameType();
   if(theGameType)
   {
      mGameType = theGameType;
      theGameType->addClientGameMenuOptions(menuItems);
   }
   GameConnection *gc = gClientGame->getConnectionToServer();
   if(gc)
   {
      if(gc->isAdmin())
         menuItems.push_back(MenuItem("ADMIN",4));
      else
         menuItems.push_back(MenuItem("ENTER ADMIN PASSWORD",5));
   }
   menuItems.push_back(MenuItem("LEAVE GAME",3));
}
void OccupanceDataIM::RegisterGameObj(TID objId, PlayerType ownerId)
{
    if (m_registeredObjects.count(objId) == 0)
        UnregisterGameObj(objId);

    RegObjEntry *pNewObj = new RegObjEntry;
    GameEntity *pGameObj = nullptr;
    GameType *pObjType = nullptr;

    pNewObj->ObjId = objId;
    pNewObj->OwnerId = ownerId;
    pNewObj->Stamped = false;

    pGameObj = g_Game->GetPlayer(ownerId)->GetEntity(objId);
    _ASSERTE(pGameObj);
    pNewObj->LastPosition = Vector2(-1, -1);

    pObjType = g_Game->GetEntityType((EntityClassType)pGameObj->TypeId());
    _ASSERTE(pObjType);

    pNewObj->ObjWidth = pObjType->P(TP_Width) + pObjType->P(TP_BuildingExpansionIncrement);
    pNewObj->ObjHeight = pObjType->P(TP_Height);

    if ((pNewObj->OwnerId == PLAYER_Self &&
        (pObjType->P(TP_IsResoureDepot) ||
        g_Game->Self()->Race()->GetResourceSource(RESOURCE_Secondary) == pGameObj->TypeId())) ||
        pObjType->P(TP_IsSecondaryResource) ||
        pObjType->P(TP_IsPrimaryResource))
    {
        pNewObj->IsAllSidePadded = true;
        pNewObj->PaddingSize = m_cellSide;

        pNewObj->ObjWidth += (2 * pNewObj->PaddingSize);
        pNewObj->ObjHeight += (2 * pNewObj->PaddingSize);
    }

    m_registeredObjects[objId] = pNewObj;
}