#if macintosh #include #else #include #endif #include #ifdef EAST_TEAM #define UN(name) EAST ## name #endif #ifdef WEST_TEAM #define UN(name) WEST ## name #endif /* Team functions */ #define InitializeGame UN(InitializeGame) #define InitializePoint UN(InitializePoint) #define WonPoint UN(WonPoint) #define LostPoint UN(LostPoint) #define GameOver UN(GameOver) #define Player1 UN(Player1) #define Player2 UN(Player2) #define Player3 UN(Player3) #define Player4 UN(Player4) /* Internal functions */ #define DoPlayer UN(DoPlayer) #define DoInitializeGame UN(DoInitializeGame) #define DoInitializePoint UN(DoInitializePoint) #define DoWonPoint UN(DoWonPoint) #define DoLostPoint UN(DoLostPoint) #define DoGameOver UN(DoGameOver) /* The name of Soccer_Init has to be dealt with specially, because Tcl assumes a particular arrangement of upper and lower case */ #ifdef EAST_TEAM #define Soccer_Init East_Init #endif #ifdef WEST_TEAM #define Soccer_Init West_Init #endif Tcl_Interp *teamInterp; char *Player1(); char *Player2(); char *Player3(); char *Player4(); void InitializeGame(); void InitializePoint(); void WonPoint(); void LostPoint(); void GameOver(); int DoPlayer(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { int x, y; int error; if (argc != 1) { interp->result = "Expected 0 arguments."; return TCL_ERROR; } teamInterp = interp; switch((int)clientData) { case 1: interp->result = Player1(); break; case 2: interp->result = Player2(); break; case 3: interp->result = Player3(); break; case 4: interp->result = Player4(); break; } return TCL_OK; } int DoInitializeGame(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { InitializeGame(); interp->result = ""; return TCL_OK; } int DoInitializePoint(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { InitializePoint(); interp->result = ""; return TCL_OK; } int DoWonPoint(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { WonPoint(); interp->result = ""; return TCL_OK; } int DoLostPoint(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { LostPoint(); interp->result = ""; return TCL_OK; } int DoGameOver(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { GameOver(); interp->result = ""; return TCL_OK; } int Soccer_Init(Tcl_Interp *interp) { teamInterp = interp; Tcl_CreateCommand(interp, "Player1", DoPlayer, (ClientData) 1, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "Player2", DoPlayer, (ClientData) 2, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "Player3", DoPlayer, (ClientData) 3, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "Player4", DoPlayer, (ClientData) 4, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "InitializeGame", DoInitializeGame, (ClientData) 4, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "InitializePoint", DoInitializePoint, (ClientData) 4, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "WonPoint", DoWonPoint, (ClientData) 4, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "LostPoint", DoLostPoint, (ClientData) 4, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "GameOver", DoGameOver, (ClientData) 4, (Tcl_CmdDeleteProc *)NULL); return TCL_OK; } int Content (char *dir, char *c) { char command[100]; int error, ret; sprintf(command, "Content %s %s", dir, c); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to Goal returned non-integer."; return TCL_ERROR; } return ret; } int Goal (char *dir) { char command[100]; int error, ret; sprintf(command, "Goal %s", dir); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to Goal returned non-integer."; return TCL_ERROR; } return ret; } int Sideline (char *dir) { char command[100]; int error, ret; sprintf(command, "Sideline %s", dir); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to Sideline returned non-integer."; return TCL_ERROR; } return ret; } char *View (char *dir) { char command[100]; sprintf(command, "View %s", dir); Tcl_Eval(teamInterp, command); return teamInterp->result; } char *BallDir () { char command[100]; sprintf(command, "BallDir"); Tcl_Eval(teamInterp, command); return teamInterp->result; } int BallDist () { char command[100]; int error, ret; sprintf(command, "BallDist"); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to BallDist returned non-integer."; return TCL_ERROR; } return ret; } char *OpponentDir (int n) { char command[100]; sprintf(command, "OpponentDir %d", n); Tcl_Eval(teamInterp, command); return teamInterp->result; } int OpponentDist (int n) { char command[100]; int error, ret; sprintf(command, "OpponentDist %d", n); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to BallDist returned non-integer."; return TCL_ERROR; } return ret; } int MyX () { char command[100]; int error, ret; sprintf(command, "MyX"); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to MyX returned non-integer."; return TCL_ERROR; } return ret; } int MyY () { char command[100]; int error, ret; sprintf(command, "MyY"); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to MyY returned non-integer."; return TCL_ERROR; } return ret; } int XSize () { char command[100]; int error, ret; sprintf(command, "XSize"); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to XSize returned non-integer."; return TCL_ERROR; } return ret; } int YSize () { char command[100]; int error, ret; sprintf(command, "YSize"); Tcl_Eval(teamInterp, command); error = Tcl_GetInt(teamInterp, teamInterp->result, &ret); if (error != TCL_OK) { teamInterp->result = "Call to YSize returned non-integer."; return TCL_ERROR; } return ret; } void Debug (char *msg) { char command[100]; sprintf(command, "Debug %s", msg); Tcl_Eval(teamInterp, command); }