• Main Page
  • Classes
  • Files
  • File List
  • File Members

code/source/PowerupUtils.cpp

Go to the documentation of this file.
00001 /*
00002  * TetriCycle
00003  * Copyright (C) 2009, 2010 Cale Scholl
00004  *
00005  * This file is part of TetriCycle.
00006  *
00007  * TetriCycle is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * TetriCycle is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with TetriCycle.  If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 /** @file PowerupUtils.cpp
00022  * @author Cale Scholl / calvinss4
00023  */
00024 
00025 #include "PowerupUtils.h"
00026 
00027 #include "Powerup.h"       // for Powerup
00028 #include "libwiigui/gui.h" // for GuiSound
00029 #include "Options.h"       // for Options
00030 #include "Player.h"        // for Player
00031 
00032 extern Options *g_options;
00033 extern Player *g_players;
00034 
00035 GuiSound *PowerupUtils::invalidTargetSound = 
00036   new GuiSound(powerup_invalid_target_pcm, powerup_invalid_target_pcm_size, SOUND_PCM);
00037 
00038 Powerup* PowerupUtils::GetStaticInstance(PowerupId pid)
00039 {
00040   return Powerup::GetVector()[pid];
00041 }
00042 
00043 GuiImageData* PowerupUtils::GetImageData(PowerupId pid)
00044 {
00045   return GetStaticInstance(pid)->GetImageData();
00046 }
00047 
00048 GuiSound* PowerupUtils::GetSound(PowerupId pid)
00049 {
00050   return GetStaticInstance(pid)->GetSound();
00051 }
00052 
00053 std::string* PowerupUtils::GetHelpText(PowerupId pid)
00054 {
00055   return GetStaticInstance(pid)->GetHelpText();
00056 }
00057 
00058 PowerupId PowerupUtils::GetNextId(Player &player)
00059 {
00060   if (g_options->players == 1)
00061     return POWERUP_ID_NONE;
00062 
00063   int powerupRate   = g_options->profile.powerupRate;
00064   Player *playerPtr = NULL;
00065 
00066   if (player.isHandicapEnabled)
00067   {
00068     powerupRate = player.profile.powerupRate;
00069     playerPtr   = &player;
00070   }
00071 
00072   if (!powerupRate)
00073     return POWERUP_ID_NONE;
00074 
00075   return ((++player.gameData.pieces + 1) % powerupRate) ? 
00076     POWERUP_ID_NONE : PowerupUtils::GetRandomId(playerPtr);
00077 }
00078 
00079 PowerupId PowerupUtils::GetRandomId(Player *playerPtr)
00080 {
00081   // Use the global options settings.
00082   int powerupsSize    = g_options->powerupsSize;
00083   PowerupId *powerups = &g_options->powerups[0];
00084 
00085   if (playerPtr)
00086   {
00087     // Use the handicap options settings.
00088     powerupsSize = playerPtr->powerupsSize;
00089     powerups     = &playerPtr->powerups[0];
00090   }
00091   
00092   return powerupsSize ? 
00093     powerups[(int)(genrand() * powerupsSize)] : POWERUP_ID_NONE;
00094 }
00095 
00096 int PowerupUtils::GetTotalPowerups()
00097 {
00098   return Powerup::GetVector().size();
00099 }
00100 
00101 void PowerupUtils::ResetPowerupStartTimes()
00102 {
00103   Powerup *powerup;
00104   for (int i = 0; i < g_options->players; ++i)
00105   {
00106     for (int j = 0; j < MAX_POWERUP_EFFECTS; ++j)
00107     {
00108       powerup = g_players[i].gameData.powerupEffects[j];
00109       if (powerup)
00110         powerup->ResetStartTime();
00111     }
00112   }
00113 }
00114 
00115 void PowerupUtils::DeleteAllPowerups()
00116 {
00117   Powerup *powerup;
00118   Player *player = g_players;
00119 
00120   for (int i = 0; i < g_options->players; ++i, ++player)
00121   {
00122     for (int j = 0; j < MAX_POWERUP_EFFECTS; ++j)
00123     {
00124       powerup = player->gameData.powerupEffects[j];
00125       if (powerup)
00126         powerup->Terminate();
00127     }
00128   }
00129 }

Generated on Wed Oct 20 2010 17:06:58 for TetriCycle by  doxygen 1.7.1