gFuns_queeshai_001

This is a collection of public global functions that people might find helpful. You can call these function from your script by including the following line at the top: #include 158 I will ensure that future changes to this script retain backwards compatibility. If you simply want the latest and greatest (and don't care about backwards compatibility), see: gFuns_queeshai.

////////////////////////////////////////////////////////////
// remove all cards from a player's deck
// 
// @param p - player of interest
// 
// jed: consider migrating to Player.removeDeck()
// 
////////////////////////////////////////////////////////////
void removeDeck( Player p )
{
  int ds = p.deckSize();
  
  for( int i = 0; i < ds; i++ )
  {
    p.removeDeckCard(0);
  }
}


////////////////////////////////////////////////////////////
// set all map terrain the same.
// 
// @param topo - {OCEAN, SOGGY, FLAT, HILLS, MOUNTAIN}
// @param veg - {DESERT, GRASS, TREES}
// 
// @example - setAllTerrain( FLAT, GRASS );
// 
// jed: consider migrating to config (alternative to random map generation)
// 
////////////////////////////////////////////////////////////
void setAllTerrain( int topo, int veg )
{
  Location el;

  int mapWidth = getMapWidth();
  int mapHeight = getMapHeight();
  
  for( int x = 0; x < mapWidth; x++ )
  {
    for( int y = 0; y < mapHeight; y++ )
    {
      el = createLocation( x, y );
      setTerrain( el, topo, veg );
    }
  }
}


////////////////////////////////////////////////////////////
// enable/disable debugging
// 
// @param b - {true, false}
// 
////////////////////////////////////////////////////////////
void setDebug( bool b )
{
  DEBUG = b;
}


////////////////////////////////////////////////////////////
// return debugging state
// 
// @return - {true, false}
// 
////////////////////////////////////////////////////////////
bool getDebug()
{
  return DEBUG;
}


////////////////////////////////////////////////////////////
// print helpful messages
// 
// @param s - string to print
// 
////////////////////////////////////////////////////////////
void msg( string s )
{
  Player p = getPlayer( 1 );
  statusMsg( p, "DEBUG: " + s );
}


////////////////////////////////////////////////////////////
// print helpful messages while coding and suppress when done
// 
// @param s - string to print
// 
////////////////////////////////////////////////////////////
void debug( string s )
{
  if( DEBUG )
  {
    msg( s );
  }
}


////////////////////////////////////////////////////////////
// safer way to add players so that code won't break when constructor is fixed.
// 
// jed: meant this to be a function overload, but I camelCased "Ai" so it is not.
// 
////////////////////////////////////////////////////////////
void addAiPlayer()
{
  addAIPlayer( "x", "x", 0 );
}


////////////////////////////////////////////////////////////
// find first duplicate card in deck; originally for highlander format
// 
// @param p - player whose deck is checked
// @return - name of first duplicate card
// 
// jed: consider migrating to Player
// 
////////////////////////////////////////////////////////////
string getFirstDeckDupe( Player p )
{
  int ds = p.deckSize();
  string[] cardNames(ds);
  
  for( int i = 0; i < ds; i++ )
  {
    cardNames[i] = p.getDeckCard( i ).getName();
    
    for( int j = 0; j < i; j++ )
    {
      if( cardNames[j] == cardNames[i] )
      {
        return cardNames[i];
      }
    }
  }
  
  return "";
}


////////////////////////////////////////////////////////////
// check to see if deck contains any duplicates; originally for highlander format
// 
// @param p - player whose deck is checked
// 
// jed: consider migrating to Player
// 
////////////////////////////////////////////////////////////
bool isDeckDupeFree( Player p )
{
  if( getFirstDeckDupe( p ) == "" )
  {
    return true;
  }
  
  return false;
}


////////////////////////////////////////////////////////////
// check deck for card
// 
// @param p - player whose deck is checked
// @param cardName - card of interest
// @return - {true, false}
// 
// jed: consider migrating to Player
// 
////////////////////////////////////////////////////////////
bool isCardInDeck( Player p, string cardName )
{
  int ds = p.deckSize();
  
  for( int i = 0; i < ds; i++ )
  {
    if( p.getDeckCard( i ).getName() == cardName )
    {
      return true;
    }
  }
  
  return false;
}


////////////////////////////////////////////////////////////
// check deck for restricted cards
// 
// @param p - player whose deck is checked
// @param restrictedCards - array of restricted cards
// @return - {true, false}
// 
// jed: consider migrating to Player
// 
////////////////////////////////////////////////////////////
bool isRestrictedCardPresent( Player p, string[] restrictedCards )
{
  for( int i = 0; i < restrictedCards.length(); i++ )
  {
    if( isCardInDeck( p, restrictedCards[i] ) )
    {
      return true;
    }
  }

  return false;
}