/* -*- Mode: C++ -*-
*Header:
*File: field.C
*Author: Noda Itsuki
*Date: 1996/01/28
*EndHeader:
*/
/*
*Copyright:
Copyright (C) 1996-2000 Electrotechnical Laboratory.
Itsuki Noda, Yasuo Kuniyoshi and Hitoshi Matsubara.
Copyright (C) 2000-2007 RoboCup Soccer Server Maintainance Group.
Patrick Riley, Tom Howard, Daniel Polani, Itsuki Noda,
Mikhail Prokopenko, Jan Wendler
This file is a part of SoccerServer.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*EndCopyright:
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "field.h"
#include "param.h"
#include "fallback.h"
#include "types.h"
#include "utility.h"
#include "netif.h"
#include "object.h"
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/AsciiText.h>
#include "mark.RoboCup.grey.xbm"
#define SMON_CONFIG ".rcssmonitor_classic"
extern Stadium Std;
static void Quit(void);
static void Start(void);
static void Update(void);
Widget foulmenu; /* for Foul Panel Shell */
static void FoulMenuPlace( Widget w, XButtonEvent* );
static void FoulMenuCheck( void );
static void FoulPanelChosen( Widget w, XtPointer );
pos_t foul_pos;
Widget discardmenu1; /* for Discard Left Team Player Panel Shell */
Widget discardmenu2; /* for Discard Right Team Player Panel Shell */
static void DiscardMenuPlace1( Widget w, XEvent* );
static void DiscardPanelChosen1( Widget w, XtPointer );
static void PopdownDiscardMenu1( Widget w );
static void DiscardMenuPlace2( Widget w, XEvent* );
static void DiscardPanelChosen2( Widget w, XtPointer );
static void PopdownDiscardMenu2( Widget w );
static XtActionsRec actions[] = {
{"FoulMenuPlace", (XtActionProc)FoulMenuPlace},
{"FoulMenuCheck", (XtActionProc)FoulMenuCheck},
{"DiscardMenuPlace1", (XtActionProc)DiscardMenuPlace1},
{"DiscardMenuPlace2", (XtActionProc)DiscardMenuPlace2},
{"PopdownDiscardMenu1", (XtActionProc)PopdownDiscardMenu1},
{"PopdownDiscardMenu2", (XtActionProc)PopdownDiscardMenu2}
};
#ifdef X11R5
static Arg Args[16];
static int Argn;
#endif
/*
*===================================================================
*Part: Stadium
*===================================================================
*/
Stadium::Stadium()
{
plog = true;
popup = false;
playtime = -1;
length_magnify = LENGTH_MAGNIFY;
board_rows = BOARD_ROWS;
std::strcpy( color_l, TEAM_L_COLOR );
std::strcpy( color_r, TEAM_R_COLOR );
std::strcpy( goalie_color_l, GOALIE_L_COLOR );
std::strcpy( goalie_color_r, GOALIE_R_COLOR );
std::strcpy( neck_color_l, NECK_L_COLOR );
std::strcpy( neck_color_r, NECK_R_COLOR );
std::strcpy( goalie_neck_color_l, GOALIE_NECK_L_COLOR );
std::strcpy( goalie_neck_color_r, GOALIE_NECK_R_COLOR );
std::strcpy( status_font, DEFAULT_STATUS_FONT);
std::strcpy( glabel_font, DEFAULT_GOAL_LABEL_FONT );
glabel_width = DEFAULT_GOAL_LABEL_WIDTH;
std::strcpy( gscore_font, DEFAULT_GOAL_SCORE_FONT );
gscore_width = DEFAULT_GOAL_SCORE_WIDTH;
std::strcpy( olabel_font, DEFAULT_OFFSIDE_LABEL_FONT );
olabel_width = DEFAULT_OFFSIDE_LABEL_WIDTH;
//std::strcpy( ball_file, DEFAULT_BALL_FILE_NAME );
std::strcpy( ball_file, "" );
psize = InDisplaySize(PLAYER_WIDGET_SIZE );
std::strcpy( pfont, DEFAULT_PLAYER_FONT );
pfont_x = DEFAULT_PLAYER_FONT_POS_X;
pfont_y = DEFAULT_PLAYER_FONT_POS_Y;
eval_flag = false;
for ( int i = 0; i < MAX_PLAYER * 2; ++i )
{
player_status[i] = false;
}
redraw = false;
stamina_max = 4000;
}
Stadium::~Stadium()
{
std::cerr << "destruct Stadium" << std::endl;
}
void
Stadium::init( int argc, char *argv[] )
{
Widget top;
static String fallback_resources[] = FALLBACK_RESOURCES;
top = XtAppInitialize( &app_context, "Stadium", NULL, 0,
&argc, argv, fallback_resources, NULL, 0 );
getOption( argc, argv );
view_dir = VIEW_FOR;
assign( top );
XtRealizeWidget( top );
no_resize( top );
field.draw();
field.ball.assign();
if ( ! port.init() )
{
std::cerr << __FILE__ << ": " << __LINE__ << ": Could not initialize port\n";
exit( 1 );
}
XtAppAddInput( app_context, port.socketfd,
(XtPointer)XtInputReadMask, (XtInputCallbackProc)Update, NULL );
}
void
Stadium::readConf( FILE* fp )
{
option_t opt[] = {
{"print_log", (void *)&plog, V_ONOFF},
{"host",(void *)&(port.host), V_STRING},
{"port",(void *)&(port.portnum), V_INT},
{"version",(void *)&(port.version), V_INT},
{"length_magnify",(void *)&(length_magnify), V_DOUBLE},
{"goal_width", (void *)&(field.gwidth), V_DOUBLE},
{"log_line", (void *)&board_rows, V_INT},
{"team_l_color", (void *)&color_l, V_STRING},
{"team_r_color", (void *)&color_r, V_STRING},
{"goalie_l_color", (void *)&goalie_color_l, V_STRING},
{"goalie_r_color", (void *)&goalie_color_r, V_STRING},
{"neck_l_color", (void *)&neck_color_l, V_STRING},
{"neck_r_color", (void *)&neck_color_r, V_STRING},
{"goalie_neck_l_color", (void *)&goalie_neck_color_l, V_STRING},
{"goalie_neck_r_color", (void *)&goalie_neck_color_r, V_STRING},
{"status_font", (void *)&status_font, V_STRING},
{"print_mark", (void *)&(field.pmark), V_ONOFF},
{"mark_file_name", (void *)&(field.mark_file), V_STRING},
{"ball_file_name", (void *)&(ball_file), V_STRING},
{"popup_msg", (void *)&popup, V_ONOFF},
{"goal_label_font", (void *)&glabel_font, V_STRING},
{"goal_label_width", (void *)&glabel_width, V_INT},
{"goal_score_font", (void *)&gscore_font, V_STRING},
{"goal_score_width", (void *)&gscore_width, V_INT},
{"offside_label_font", (void *)&olabel_font, V_STRING},
{"offside_label_width", (void *)&olabel_width, V_INT},
{"player_widget_size", (void *)&(psize), V_DOUBLE},
{"player_widget_font", (void *)&(pfont), V_STRING},
{"uniform_num_pos_x", (void *)&(pfont_x), V_INT},
{"uniform_num_pos_y", (void *)&(pfont_y), V_INT},
{"eval", (void *)&(eval_flag), V_ONOFF},
{"redraw_player", (void *)&(redraw), V_ONOFF},
{"\0", NULL, 0}
};
char buf[MaxMesg];
char com[256];
char onoff[16];
while ( std::fgets( buf,MaxMesg,fp ) != NULL )
{
/* ignore remark line */
if (buf[0] == '#' || buf[0] == '\n')
continue;
/* replace from ':' to ' ' */
char *r = buf;
while(*r != NULLCHAR)
{
if (*r == ':') *r = ' ';
r++;
}
int n = std::sscanf( buf, "%s", com );
if ( n < 1 )
{
std::cerr << "Illegal line : " << buf;
continue;
}
int p = 0;
for ( p = 0; opt[p].vptr != NULL; ++p )
{
if ( std::strcmp( com, opt[p].optname ) )
continue;
/* match */
switch ( opt[p].vsize ) {
case V_INT:
n = std: