2011-02-10 07:17:18 +01:00
|
|
|
/* -*- compile-command: "cd ../linux && make -j3 MEMDEBUG=TRUE"; -*- */
|
2003-11-01 06:35:29 +01:00
|
|
|
/*
|
2011-02-10 07:17:18 +01:00
|
|
|
* Copyright 2001-2011 by Eric House (xwords@eehouse.org). All rights
|
2009-01-04 00:54:25 +01:00
|
|
|
* reserved.
|
2003-11-01 06:35:29 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GAME_H_
|
|
|
|
#define _GAME_H_
|
|
|
|
|
|
|
|
#include "model.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "comms.h"
|
|
|
|
#include "server.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#ifdef CPLUS
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-10-04 15:44:29 +02:00
|
|
|
#define STREAM_SAVE_PREVWORDS 0x11
|
2011-07-04 21:51:00 +02:00
|
|
|
#define STREAM_VERS_SERVER_SAVES_TOSHOW 0x10
|
2011-04-02 04:57:10 +02:00
|
|
|
#define STREAM_VERS_PLAYERDICTS 0x0F
|
2011-02-10 07:17:18 +01:00
|
|
|
#define STREAM_SAVE_PREVMOVE 0x0E /* server saves prev move explanation */
|
|
|
|
#define STREAM_VERS_ROBOTIQ STREAM_SAVE_PREVMOVE /* robots have different smarts */
|
2010-09-01 15:51:44 +02:00
|
|
|
#define STREAM_VERS_DICTLANG 0x0D /* save dict lang code in CurGameInfo */
|
2010-07-03 20:25:01 +02:00
|
|
|
#define STREAM_VERS_NUNDONE 0x0C /* save undone tile in model */
|
2010-05-14 14:42:53 +02:00
|
|
|
#define STREAM_VERS_GAMESECONDS 0x0B /* save gameSeconds whether or not
|
|
|
|
timer's enabled */
|
2010-01-07 15:47:01 +01:00
|
|
|
#define STREAM_VERS_4YOFFSET 0x0A /* 4 bits for yOffset on board */
|
2009-09-26 16:37:49 +02:00
|
|
|
#define STREAM_VERS_CHANNELSEED 0x09 /* new short in relay connect must be
|
|
|
|
saved in comms */
|
2009-04-05 21:16:52 +02:00
|
|
|
#define STREAM_VERS_UTF8 0x08
|
2009-01-04 00:54:25 +01:00
|
|
|
#define STREAM_VERS_ALWAYS_MULTI 0x07 /* stream format same for multi and
|
|
|
|
one-device game builds */
|
2008-09-09 14:18:32 +02:00
|
|
|
#define STREAM_VERS_MODEL_NO_DICT 0x06
|
2007-12-14 04:38:55 +01:00
|
|
|
#define STREAM_VERS_BLUETOOTH 0x05
|
2006-11-05 17:54:18 +01:00
|
|
|
#define STREAM_VERS_KEYNAV 0x04
|
2006-10-05 03:17:03 +02:00
|
|
|
#define STREAM_VERS_RELAY 0x03
|
|
|
|
#define STREAM_VERS_41B4 0x02
|
2004-10-09 01:57:24 +02:00
|
|
|
#define STREAM_VERS_405 0x01
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2011-10-04 15:44:29 +02:00
|
|
|
#define CUR_STREAM_VERS STREAM_SAVE_PREVWORDS
|
2006-10-05 03:17:03 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
typedef struct LocalPlayer {
|
|
|
|
XP_UCHAR* name;
|
|
|
|
XP_UCHAR* password;
|
2011-04-02 04:57:10 +02:00
|
|
|
XP_UCHAR* dictName;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 secondsUsed;
|
|
|
|
XP_Bool isLocal;
|
2011-01-10 15:44:28 +01:00
|
|
|
XP_U8 robotIQ; /* 0 means not a robot; 1-100 means how
|
|
|
|
dumb is it with 1 meaning very smart */
|
2003-11-01 06:35:29 +01:00
|
|
|
} LocalPlayer;
|
|
|
|
|
2011-01-10 15:44:28 +01:00
|
|
|
#define LP_IS_ROBOT(lp) ((lp)->robotIQ != 0)
|
|
|
|
#define LP_IS_LOCAL(lp) ((lp)->isLocal)
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
#define DUMB_ROBOT 0
|
|
|
|
#define SMART_ROBOT 1
|
|
|
|
|
|
|
|
typedef struct CurGameInfo {
|
|
|
|
XP_UCHAR* dictName;
|
|
|
|
LocalPlayer players[MAX_NUM_PLAYERS];
|
2008-05-31 05:26:16 +02:00
|
|
|
XP_U16 gameID; /* uniquely identifies game */
|
|
|
|
XP_U16 gameSeconds; /* for timer */
|
2010-09-01 15:51:44 +02:00
|
|
|
XP_LangCode dictLang;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U8 nPlayers;
|
|
|
|
XP_U8 boardSize;
|
2007-02-02 09:34:37 +01:00
|
|
|
DeviceRole serverRole;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_Bool hintsNotAllowed;
|
|
|
|
XP_Bool timerEnabled;
|
2003-11-19 05:06:32 +01:00
|
|
|
XP_Bool allowPickTiles;
|
2004-06-18 15:16:40 +02:00
|
|
|
XP_Bool allowHintRect;
|
2003-11-01 06:35:29 +01:00
|
|
|
XWPhoniesChoice phoniesAction;
|
2007-12-14 04:38:55 +01:00
|
|
|
XP_Bool confirmBTConnect; /* only used for BT */
|
2003-11-01 06:35:29 +01:00
|
|
|
} CurGameInfo;
|
|
|
|
|
2011-03-11 03:13:56 +01:00
|
|
|
typedef struct _GameStateInfo {
|
|
|
|
XP_U16 visTileCount;
|
|
|
|
XP_Bool canHint;
|
|
|
|
XP_Bool canRedo;
|
|
|
|
XP_Bool inTrade;
|
2011-09-10 04:04:25 +02:00
|
|
|
XP_Bool tradeTilesSelected;
|
2011-03-11 03:13:56 +01:00
|
|
|
XP_Bool gameIsConnected;
|
|
|
|
XP_Bool canShuffle;
|
|
|
|
} GameStateInfo;
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
typedef struct XWGame {
|
|
|
|
BoardCtxt* board;
|
|
|
|
ModelCtxt* model;
|
|
|
|
ServerCtxt* server;
|
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
CommsCtxt* comms;
|
|
|
|
#endif
|
|
|
|
} XWGame;
|
|
|
|
|
|
|
|
void game_makeNewGame( MPFORMAL XWGame* game, CurGameInfo* gi,
|
2010-01-31 22:35:07 +01:00
|
|
|
XW_UtilCtxt* util, DrawCtx* draw,
|
2011-08-01 07:23:46 +02:00
|
|
|
CommonPrefs* cp, const TransportProcs* procs
|
|
|
|
#ifdef SET_GAMESEED
|
|
|
|
,XP_U16 gameSeed
|
|
|
|
#endif
|
|
|
|
);
|
2005-04-03 03:36:59 +02:00
|
|
|
void game_reset( MPFORMAL XWGame* game, CurGameInfo* gi, XW_UtilCtxt* util,
|
2010-01-31 22:35:07 +01:00
|
|
|
CommonPrefs* cp, const TransportProcs* procs );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2006-11-05 17:54:18 +01:00
|
|
|
XP_Bool game_makeFromStream( MPFORMAL XWStreamCtxt* stream, XWGame* game,
|
2011-04-02 04:57:10 +02:00
|
|
|
CurGameInfo* gi, DictionaryCtxt* dict,
|
|
|
|
const PlayerDicts* dicts, XW_UtilCtxt* util,
|
2006-11-05 17:54:18 +01:00
|
|
|
DrawCtx* draw, CommonPrefs* cp,
|
2009-09-12 23:39:13 +02:00
|
|
|
const TransportProcs* procs );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2006-09-15 09:31:24 +02:00
|
|
|
void game_saveToStream( const XWGame* game, const CurGameInfo* gi,
|
|
|
|
XWStreamCtxt* stream );
|
2003-11-01 06:35:29 +01:00
|
|
|
void game_dispose( XWGame* game );
|
2011-03-11 03:13:56 +01:00
|
|
|
|
|
|
|
void game_getState( const XWGame* game, GameStateInfo* gsi );
|
|
|
|
|
2007-02-03 18:54:20 +01:00
|
|
|
void gi_initPlayerInfo( MPFORMAL CurGameInfo* gi,
|
|
|
|
const XP_UCHAR* nameTemplate );
|
2003-11-01 06:35:29 +01:00
|
|
|
void gi_disposePlayerInfo( MPFORMAL CurGameInfo* gi );
|
2006-09-15 09:31:24 +02:00
|
|
|
void gi_writeToStream( XWStreamCtxt* stream, const CurGameInfo* gi );
|
2004-06-24 07:18:46 +02:00
|
|
|
void gi_readFromStream( MPFORMAL XWStreamCtxt* stream, CurGameInfo* gi );
|
2007-12-31 21:00:13 +01:00
|
|
|
void gi_copy( MPFORMAL CurGameInfo* destGI, const CurGameInfo* srcGi );
|
2010-09-10 10:30:40 +02:00
|
|
|
XP_U16 gi_countLocalPlayers( const CurGameInfo* gi, XP_Bool humanOnly );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_Bool player_hasPasswd( LocalPlayer* player );
|
|
|
|
XP_Bool player_passwordMatches( LocalPlayer* player, XP_U8* buf, XP_U16 len );
|
|
|
|
XP_U16 player_timePenalty( CurGameInfo* gi, XP_U16 playerNum );
|
|
|
|
|
|
|
|
#ifdef CPLUS
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|