Ejemplo n.º 1
0
unit* game_board::get_visible_unit(const map_location &loc,
	const team &current_team, bool see_all)
{
	unit_map::iterator ui = find_visible_unit(loc, current_team, see_all);
	if (ui == units_.end()) return nullptr;
	return &*ui;
}
void playsingle_controller::demolish()
{
	unit_map::iterator u_itor = find_visible_unit(mouse_handler_.get_selected_hex(), teams_[player_number_ -1]);
	if (!browse_ && u_itor.valid()) {
		menu_handler_.demolish(mouse_handler_, &*u_itor);
	}
}
Ejemplo n.º 3
0
void playsingle_controller::advance()
{
	unit* u_itor = find_visible_unit(mouse_handler_.get_selected_hex(), teams_[player_number_ -1]);
	if (!browse_ && u_itor) {
		menu_handler_.advance(mouse_handler_, u_itor);
	}
}
Ejemplo n.º 4
0
void game_display::display_unit_hex(map_location hex)
{
	unit_map::const_iterator u = find_visible_unit(units_, hex, get_map(), teams_, teams_[viewing_team()], !viewpoint_);
	if (u != units_.end()) {
		displayedUnitHex_ = hex;
		invalidate_unit();
	}
}
Ejemplo n.º 5
0
/****************************************************************************
  Return color for overview map tile.
****************************************************************************/
static struct color *overview_tile_color(struct tile *ptile)
{
  if (overview.layers[OLAYER_CITIES]) {
    struct city *pcity = tile_city(ptile);

    if (pcity) {
      if (NULL == client.conn.playing
          || city_owner(pcity) == client.conn.playing) {
	return get_color(tileset, COLOR_OVERVIEW_MY_CITY);
      } else if (pplayers_allied(city_owner(pcity), client.conn.playing)) {
	/* Includes teams. */
	return get_color(tileset, COLOR_OVERVIEW_ALLIED_CITY);
      } else {
	return get_color(tileset, COLOR_OVERVIEW_ENEMY_CITY);
      }
    }
  }
  if (overview.layers[OLAYER_UNITS]) {
    struct unit *punit = find_visible_unit(ptile);

    if (punit) {
      if (NULL == client.conn.playing
          || unit_owner(punit) == client.conn.playing) {
	return get_color(tileset, COLOR_OVERVIEW_MY_UNIT);
      } else if (pplayers_allied(unit_owner(punit), client.conn.playing)) {
	/* Includes teams. */
	return get_color(tileset, COLOR_OVERVIEW_ALLIED_UNIT);
      } else {
	return get_color(tileset, COLOR_OVERVIEW_ENEMY_UNIT);
      }
    }
  }
  if (overview.layers[OLAYER_BORDERS]) {
    struct player *owner = tile_owner(ptile);

    if (owner) {
      if (overview.layers[OLAYER_BORDERS_ON_OCEAN]) {
        return get_player_color(tileset, owner);
      } else if (!is_ocean_tile(ptile)) {
        return get_player_color(tileset, owner);
      }
    }
  }
  if (overview.layers[OLAYER_RELIEF] && tile_terrain(ptile) != T_UNKNOWN) {
    return get_terrain_color(tileset, tile_terrain(ptile));
  }
  if (overview.layers[OLAYER_BACKGROUND] && tile_terrain(ptile) != T_UNKNOWN) {
    if (is_ocean_tile(ptile)) {
      return get_color(tileset, COLOR_OVERVIEW_OCEAN);
    } else {
      return get_color(tileset, COLOR_OVERVIEW_LAND);
    }
  }

  return get_color(tileset, COLOR_OVERVIEW_UNKNOWN);
}
Ejemplo n.º 6
0
void game_display::highlight_hex(map_location hex)
{
	unit_map::const_iterator u = find_visible_unit(units_, hex, get_map(), teams_, teams_[viewing_team()], !viewpoint_);
	if (u != units_.end()) {
		displayedUnitHex_ = hex;
		invalidate_unit();
	} else {
		u = find_visible_unit(units_, mouseoverHex_, get_map(), teams_, teams_[viewing_team()], !viewpoint_);
		if (u != units_.end()) {
			// mouse moved from unit hex to non-unit hex
			if (units_.count(selectedHex_)) {
				displayedUnitHex_ = selectedHex_;
				invalidate_unit();
			}
		}
	}

	display::highlight_hex(hex);
	invalidate_game_status();
}
Ejemplo n.º 7
0
image::TYPE game_display::get_image_type(const map_location& loc) {
	// We highlight hex under the mouse, or under a selected unit.
	if (get_map().on_board(loc)) {
		if (loc == mouseoverHex_ || loc == attack_indicator_src_) {
			return image::BRIGHTENED;
		} else if (loc == selectedHex_) {
			unit_map::iterator un = find_visible_unit(units_, loc, get_map(),
					teams_, teams_[currentTeam_], !viewpoint_);
			if (un != units_.end() && !un->second.get_hidden()) {
				return image::BRIGHTENED;
			}
		}
	}
	return image::SCALED_TO_HEX;
}
Ejemplo n.º 8
0
/**************************************************************************
  Popup a label with information about the tile, unit, city, when the user
  used the middle mouse button on the map.
**************************************************************************/
static void popit(GdkEventButton *event, struct tile *ptile)
{
  GtkWidget *p;
  static struct tmousepos mousepos;
  struct unit *punit;

  if (TILE_UNKNOWN != client_tile_get_known(ptile)) {
    p=gtk_window_new(GTK_WINDOW_POPUP);
    gtk_widget_set_app_paintable(p, TRUE);
    gtk_container_set_border_width(GTK_CONTAINER(p), 4);
    gtk_container_add(GTK_CONTAINER(p), gtk_label_new(popup_info_text(ptile)));

    punit = find_visible_unit(ptile);

    if (punit) {
      mapdeco_set_gotoroute(punit);
      if (punit->goto_tile) {
        mapdeco_set_crosshair(punit->goto_tile, TRUE);
      }
    }
    mapdeco_set_crosshair(ptile, TRUE);

    g_signal_connect(p, "destroy",
		     G_CALLBACK(popupinfo_popdown_callback), NULL);

    mousepos.x = event->x;
    mousepos.y = event->y;

    g_signal_connect(p, "size-allocate",
		     G_CALLBACK(popupinfo_positioning_callback), 
		     &mousepos);

    gtk_widget_show_all(p);
    gdk_device_grab(event->device, gtk_widget_get_window(p),
                    GDK_OWNERSHIP_NONE, TRUE, GDK_BUTTON_RELEASE_MASK, NULL,
                    event->time);
    gtk_grab_add(p);

    g_signal_connect_after(p, "button_release_event",
                           G_CALLBACK(popit_button_release), NULL);
  }
}
Ejemplo n.º 9
0
inline unit_map::const_iterator find_visible_unit(const unit_map &units,
        const map_location &loc, const team &current_team, bool see_all = false)
{
    return find_visible_unit(const_cast<unit_map &>(units), loc,
                             current_team, see_all);
}
Ejemplo n.º 10
0
/**************************************************************************
...
**************************************************************************/
static void popit(int xin, int yin, struct tile *ptile)
{
  Position x, y;
  int dw, dh;
  Dimension w, h, b;
  static struct tile *cross_list[2+1];
  struct tile **cross_head = cross_list;
  int i;
  struct unit *punit;
  char *content;
  static bool is_orders;
  
  if (TILE_UNKNOWN != client_tile_get_known(ptile)) {
    Widget p=XtCreatePopupShell("popupinfo", simpleMenuWidgetClass,
				map_canvas, NULL, 0);
    content = (char *) popup_info_text(ptile);
    /* content is provided to us as a single string with multiple lines,
       but xaw doens't support multi-line labels.  So we break it up.
       We mangle it in the process, but who cares?  It's never going to be
       used again anyway. */
    while (1) {
      char *end = strchr(content, '\n'); 
      if (end) {
	*end='\0';
      }
      XtCreateManagedWidget(content, smeBSBObjectClass, p, NULL, 0);
      if (end) {
	content = end+1;
      } else {
	break;
      }
    }

    punit = find_visible_unit(ptile);
    is_orders = show_unit_orders(punit);
    if (punit && punit->goto_tile) {
      *cross_head = punit->goto_tile;
      cross_head++;
    }
    *cross_head = ptile;
    cross_head++;

    xin /= tileset_tile_width(tileset);
    xin *= tileset_tile_width(tileset);
    yin /= tileset_tile_height(tileset);
    yin *= tileset_tile_height(tileset);
    xin += (tileset_tile_width(tileset) / 2);
    XtTranslateCoords(map_canvas, xin, yin, &x, &y);
    dw = XDisplayWidth (display, screen_number);
    dh = XDisplayHeight (display, screen_number);
    XtRealizeWidget(p);
    XtVaGetValues(p, XtNwidth, &w, XtNheight, &h, XtNborderWidth, &b, NULL);
    w += (2 * b);
    h += (2 * b);
    x -= (w / 2);
    y -= h;
    if ((x + w) > dw) x = dw - w;
    if (x < 0) x = 0;
    if ((y + h) > dh) y = dh - h;
    if (y < 0) y = 0;
    XtVaSetValues(p, XtNx, x, XtNy, y, NULL);

    *cross_head = NULL;
    for (i = 0; cross_list[i]; i++) {
      put_cross_overlay_tile(cross_list[i]);
    }
    XtAddCallback(p,XtNpopdownCallback,popupinfo_popdown_callback,
		  (XtPointer)&is_orders);

    XtPopupSpringLoaded(p);
  }
  
}
Ejemplo n.º 11
0
 unit_map::iterator find_visible_unit(const map_location & loc, size_t team, bool see_all = false) {
     return find_visible_unit(loc, teams_[team], see_all);
 }
void playsingle_controller::execute_guard_attack(int team_index)
{
	// art maybe advance, tiles must be copy
	static map_location tiles[24];
	team& current_team = teams_[team_index - 1];
	battle_context* bc = NULL;
	const std::vector<artifical*> holded_cities = current_team.holded_cities();
	for (std::vector<artifical*>::const_iterator itor = holded_cities.begin(); itor != holded_cities.end(); ++ itor) {
		artifical& city = **itor;

		std::vector<artifical*> arts = city.field_arts();
		for (std::vector<artifical*>::iterator i2 = arts.begin(); i2 != arts.end(); ++ i2) {
			unit* art = *i2;

			int weapon_index = art->guard_attack();
			if (weapon_index < 0) {
				continue;
			}
			std::vector<attack_type>& attacks = art->attacks();
			const attack_type& weapon = attacks[weapon_index];
			const std::string& range = weapon.range();
			size_t adjacent_size;

			if (range == "melee") {
				// range: 1
				adjacent_size = art->adjacent_size_;
				std::copy(art->adjacent_, art->adjacent_ + adjacent_size, tiles);
			} else if (range == "ranged") {
				// range: 2
				adjacent_size = art->adjacent_size_2_;
				std::copy(art->adjacent_2_, art->adjacent_2_ + adjacent_size, tiles);
			} else {
				// other to range: 3
				adjacent_size = art->adjacent_size_3_;
				std::copy(art->adjacent_3_, art->adjacent_3_ + adjacent_size, tiles);
			}
			
			for (size_t j = 0; j != adjacent_size; ++j) {
				unit_map::iterator opp = find_visible_unit(tiles[j], current_team);
				if (!opp.valid() || !current_team.is_enemy(opp->side())) {
					continue;
				}
				if (bc) {
					*bc = battle_context(units_, *art, *opp, weapon_index, -1, 0.5, NULL);
				} else {
					bc = new battle_context(units_, *art, *opp, weapon_index, -1, 0.5, NULL);
				}
				std::pair<map_location, map_location> to_locs = attack_enemy(art, &*opp, bc->get_attacker_stats().attack_num, bc->get_defender_stats().attack_num);
				// attacker maybe advance. it is necessary that reget art.
				unit_map::iterator u = units_.find(to_locs.first);
				if (u == units_.end()) {
					break;
				} else {
					art = &*u;
					art->set_attacks(art->attacks_total());
				}
			}

		}
	}
	if (bc) {
		delete bc;
	}
}
Ejemplo n.º 13
0
/**************************************************************************
  Make a chat link at the current position or make the current selection
  clickable.
**************************************************************************/
void inputline_make_chat_link(struct tile *ptile, bool unit)
{
  char buf[MAX_LEN_MSG];
  GtkWidget *entry = toolkit.entry;
  GtkEditable *editable = GTK_EDITABLE(entry);
  gint start_pos, end_pos;
  gchar *chars;
  struct unit *punit;

  /* Get the target. */
  if (unit) {
    punit = find_visible_unit(ptile);
    if (!punit) {
      output_window_append(ftc_client, _("No visible unit on this tile."));
      return;
    }
  } else {
    punit = NULL;
  }

  if (gtk_editable_get_selection_bounds(editable, &start_pos, &end_pos)) {
    /* There is a selection, make it clickable. */
    gpointer target;
    enum text_link_type type;

    chars = gtk_editable_get_chars(editable, start_pos, end_pos);
    if (punit) {
      type = TLT_UNIT;
      target = punit;
    } else if (tile_city(ptile)) {
      type = TLT_CITY;
      target = tile_city(ptile);
    } else {
      type = TLT_TILE;
      target = ptile;
    }

    if (0 != featured_text_apply_tag(chars, buf, sizeof(buf), TTT_LINK,
                                     0, FT_OFFSET_UNSET, type, target)) {
      /* Replace the selection. */
      gtk_editable_delete_text(editable, start_pos, end_pos);
      end_pos = start_pos;
      gtk_editable_insert_text(editable, buf, -1, &end_pos);
      gtk_widget_grab_focus(entry);
      gtk_editable_select_region(editable, start_pos, end_pos);
    }
  } else {
    /* Just insert the link at the current position. */
    start_pos = gtk_editable_get_position(editable);
    end_pos = start_pos;
    chars = gtk_editable_get_chars(editable, MAX(start_pos - 1, 0),
                                   start_pos + 1);
    if (punit) {
      sz_strlcpy(buf, unit_link(punit));
    } else if (tile_city(ptile)) {
      sz_strlcpy(buf, city_link(tile_city(ptile)));
    } else {
      sz_strlcpy(buf, tile_link(ptile));
    }

    if (start_pos > 0 && strlen(chars) > 0 && chars[0] != ' ') {
      /* Maybe insert an extra space. */
      gtk_editable_insert_text(editable, " ", 1, &end_pos);
    }
    gtk_editable_insert_text(editable, buf, -1, &end_pos);
    if (chars[start_pos > 0 ? 1 : 0] != '\0'
        && chars[start_pos > 0 ? 1 : 0] != ' ') {
      /* Maybe insert an extra space. */
      gtk_editable_insert_text(editable, " ", 1, &end_pos);
    }
    gtk_widget_grab_focus(entry);
    gtk_editable_set_position(editable, end_pos);
  }

  g_free(chars);
}