Ejemplo n.º 1
0
static gboolean
game_handle_io (GGZMod * mod)
{
  int op = -1;

  fd = ggzmod_get_server_fd (mod);

  // Read the fd
  if (ggz_read_int (fd, &op) < 0) {
    ggz_error_msg ("Couldn't read the game fd");
    return FALSE;
  }

  switch (op) {
  case GN_MSG_SEAT:
    get_seat ();
    break;
  case GN_MSG_PLAYERS:
    get_players ();
    break;

  case GN_MSG_START:
    gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), MAIN_PAGE);
    new_game ();
    break;

  case GN_MSG_SYNC:
    get_sync ();
    break;

  case GN_MSG_MOVE:
    get_move ();
    break;

  case GN_MSG_SETTINGS:
    get_settings ();
    break;

  case GN_MSG_BONI:
    get_boni ();
    break;

  case GN_MSG_NOBONI:
    get_noboni ();
    break;

  default:
    ggz_error_msg ("Incorrect opcode   %d \n", op);
    break;
  }

  return TRUE;
}
Ejemplo n.º 2
0
static void put_global_message(char *mark, char *msg)
{
	global_message_list_t *gml;
	ggz_debug(DBG_MISC,
		    "Setting global message for '%s'.  Length is %zd.", mark,
		    strlen(msg));

	if (!mark || !msg)
		ggz_error_msg("put_global_message called on NULL string.");

	for (gml = game.message_head; gml != NULL; gml = gml->next) {
		if (!strcmp(mark, gml->mark)) {
			ggz_free(gml->message);
			gml->message = ggz_strdup(msg);
			return;
		}
	}

	gml = ggz_malloc(sizeof(global_message_list_t));
	gml->mark = ggz_strdup(mark);
	gml->message = ggz_strdup(msg);
	if (game.message_tail)
		game.message_tail->next = gml;
	game.message_tail = gml;
	if (!game.message_head)
		game.message_head = gml;
}
Ejemplo n.º 3
0
Archivo: state.c Proyecto: ralight/ggz
void _ggzcore_state_transition(GGZTransID trans, GGZStateID *cur)
{
	int i = 0;
	struct _GGZTransition *transitions;
	GGZStateID next = -1;

	transitions = _ggz_states[*cur].transitions;

	/* Look through valid transitions to see if this one is OK */
	while (transitions[i].id != -1) {
		if (transitions[i].id == trans) {
			next = transitions[i].next;
			break;
		}
		++i;
	}

	if (next != *cur && next != -1) {
		ggz_debug(GGZCORE_DBG_STATE, "State transition %s -> %s",
			  _ggz_states[*cur].name,
			  _ggz_states[next].name);
		*cur = next;
	} else if (next == -1) {
		ggz_error_msg("No state transition for %d from %s!",
			      trans, _ggz_states[*cur].name);
	}
}
Ejemplo n.º 4
0
void set_player_message(player_t p)
{
	if (game.data == NULL) {
		/* silently fail; it's easier to check here than elsewhere */
		return;
	}

	ggz_debug(DBG_MISC, "Setting player %d/%s's message.", p,
		    get_player_name(p));
	if (p < 0 || p >= game.num_players)
		ggz_error_msg("set_player_message(%d) called.", p);
	game.data->set_player_message(p);
	broadcast_player_message(game.players[p].seat);
}
Ejemplo n.º 5
0
Archivo: map.c Proyecto: ralight/ggz
void map_load(combat_game * _game, char *filename, gboolean *changed)
{
	int handle;
	unsigned int hash;
	char hash_str[32];
	char *new_filename;
	char *options;
	int a, b;
	char *terrain_data;

	if (changed) *changed = FALSE;

	handle = ggz_conf_parse(filename, GGZ_CONF_RDONLY);
	if (handle < 0) {
		fprintf(stderr, "Couldn't load map %s.\n", filename);
		assert(0);
		return;
	}
	/* Get the data from the file */
	// Width / Height
	_game->width = ggz_conf_read_int(handle, "map", "width", 10);
	_game->height = ggz_conf_read_int(handle, "map", "height", 10);
	for (a = 0; a < 12; a++) {
		ARMY(_game, a) =
		    ggz_conf_read_int(handle, "army", file_unit_name[a],
				      0);
	}
	// Terrain data
	terrain_data = ggz_conf_read_string(handle, "map", "data", NULL);
	_game->map =
	    (tile *) ggz_malloc(_game->width * _game->height *
				sizeof(tile));
	if (terrain_data) {
		a = strlen(terrain_data);
		while (--a >= 0) {
			switch (terrain_data[a]) {
			case 'O':
				_game->map[a].type = T_OPEN;
				break;
			case 'L':
				_game->map[a].type = T_LAKE;
				break;
			case 'N':
				_game->map[a].type = T_NULL;
				break;
			case '1':
				_game->map[a].type = OWNER(0) + T_OPEN;
				break;
			case '2':
				_game->map[a].type = OWNER(1) + T_OPEN;
				break;
			default:
				_game->map[a].type = T_OPEN;
				break;
			}
		}
	}
	// Options
	options = ggz_conf_read_string(handle, "options", "bin1", NULL);
	if (options)
		sscanf(options, "%lx", &_game->options);
	a = strlen(filename) - 1;
	while (a >= 0 && filename[a] != '/')
		a--;
	b = a + 1;
	while (b < strlen(filename) && filename[b] != '.')
		b++;
	_game->name = (char *)ggz_malloc(b - a);
	strncpy(_game->name, filename + a + 1, b - a - 1);
	_game->name[b - a - 1] = 0;

	// Well, now that we have loaded the map, let's check it's hash!
	hash = _generate_hash((char*)combat_options_string_write(_game, 1));
	snprintf(hash_str, sizeof(hash_str), ".%u", hash);
	if (strstr(filename, hash_str) == NULL) {
		// Hash don't match!!
		ggz_error_msg
		    ("Filename for map %s should be %s.%u, and not %s",
		     _game->name, _game->name, hash, filename);
		// Let's rename it!
		new_filename =
		    (char *)ggz_malloc(strlen(filename) +
				       strlen(hash_str) + 14);
		for (a = strlen(filename); a >= 0; a--) {
			if (filename[a] == '.')
				break;
		}
		strncpy(new_filename, filename, a);
		new_filename[a] = 0;
		strcat(new_filename, hash_str);
		if (rename(filename, new_filename) != 0) {
			/* I have no idea why != 0 is used as the comparison
			   here.  It seems quite wrong. */
			if (changed) *changed = TRUE;
		}
	};
}
Ejemplo n.º 6
0
Archivo: table.c Proyecto: ralight/ggz
/* Setup all table data that's not initialized by table_initialize.  This may
   be called multiple times (for instance, to resize the table), and it's not
   called until the server tells us how big the table must be. */
void table_setup(void)
{
	/* TODO: we really should draw something before this point, since the
	   player needs to see who's playing.  However, for now this will
	   work.  The problem is that before you choose what game you're
	   playing, the server doesn't know how many seats there are so it
	   just tells us 0 - even if there are players already connected. */
	if (ggzcards.num_players == 0) {
		ggz_error_msg("table_setup: num_players is zero.");
		return;
	}
	if (get_max_hand_size() == 0) {
		ggz_error_msg("table_setup: max hand size is zero.");
		return;
	}
	if (get_card_width(0) == 0 || get_card_height(0) == 0) {
		ggz_error_msg("table_setup: max card size is zero.");
		return;
	}

	if (!game_started) {
		/* If we join a game in progress, this can happen.  Probably
		   it should be fixed... */
		ggz_error_msg("ERROR - table_setup() called "
			      "without a game started.");
		game_started = TRUE;
	}

	ggz_debug(DBG_TABLE,
		  "Setting up table." "  Width and height are %d."
		  "  %d players.", get_table_width(),
		  ggzcards.num_players);

	/* We may need to resize the table */
	gtk_widget_set_size_request(table, get_table_width(),
				    get_table_height());
	gtk_widget_set_size_request(table_drawing_area,
				    get_table_width(), get_table_height());

	/* And resize the table buffer... */
	/* Note: I'm not entirely sure how reference counts work for gdk. I
	   assume that when I create a new pixmap (as below), it starts with a 
	   refcount of 1.  In that case, this code should correctly free the
	   pixmap when it is discarded. */
	assert(table_buf);
	g_object_unref(table_buf);
	table_buf = gdk_pixmap_new(table->window,
				   get_table_width(), get_table_height(),
				   -1);

	/* Resize the animation buffer. */
	anim_setup();

	/* _Now_ we're ready to draw stuff. */
	table_ready = TRUE;

	/* Revert to having no selected card. */
	selected_card = -1;

	/* Redraw and display the table. */
	table_redraw();
}