Example #1
0
/**************************************************************************
...
**************************************************************************/
static void sha_unit_new(int id)
{
  struct unit *punit = game_find_unit_by_number(id);
  struct unit *pold_unit = create_unit_virtual(unit_owner(punit), NULL, 0, 0);

  freelog(LOG_DEBUG, "sha got unit: %d", id);

  *pold_unit = *punit;
  unit_list_prepend(previous_units, pold_unit);
}
Example #2
0
/**************************************************************************
...
**************************************************************************/
static void sha_unit_change(int id)
{
  struct unit *punit = game_find_unit_by_number(id);
  struct unit *pold_unit = unit_list_find(previous_units, id);

  freelog(LOG_DEBUG, "sha got unit: %d", id);

  assert(pold_unit);
  *pold_unit = *punit;
}
Example #3
0
/**************************************************************************
  Log message for bodyguards. They will appear like this
    2: Polish Mech. Inf.[485] bodyguard (38,22){Riflemen:574@37,23} was ...
  note that these messages are likely to wrap if long.
**************************************************************************/
void BODYGUARD_LOG(int level, const struct unit *punit, const char *msg)
{
  char buffer[500];
  int minlevel = MIN(LOGLEVEL_BODYGUARD, level);
  const struct unit *pcharge;
  const struct city *pcity;
  int id = -1;
  int charge_x = -1;
  int charge_y = -1;
  const char *type = "guard";
  const char *s = "none";

  if (punit->debug) {
    minlevel = LOG_TEST;
  } else if (minlevel > fc_log_level) {
    return;
  }

  pcity = game_find_city_by_number(punit->ai.charge);
  pcharge = game_find_unit_by_number(punit->ai.charge);
  if (pcharge) {
    charge_x = pcharge->tile->x;
    charge_y = pcharge->tile->y;
    id = pcharge->id;
    type = "bodyguard";
    s = unit_rule_name(pcharge);
  } else if (pcity) {
    charge_x = pcity->tile->x;
    charge_y = pcity->tile->y;
    id = pcity->id;
    type = "cityguard";
    s = city_name(pcity);
  }
  /* else perhaps the charge died */

  my_snprintf(buffer, sizeof(buffer),
              "%s %s[%d] %s (%d,%d){%s:%d@%d,%d} ",
              nation_rule_name(nation_of_unit(punit)),
              unit_rule_name(punit),
              punit->id,
              type,
              TILE_XY(punit->tile),
	      s, id, charge_x, charge_y);
  cat_snprintf(buffer, sizeof(buffer), "%s", msg);
  if (punit->debug) {
    notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer);
  }
  freelog(minlevel, "%s", buffer);
}
Example #4
0
/****************************************************************
  Fills the buf with proper text which should be displayed on 
  the helpbuild wonder button.
*****************************************************************/
static void get_help_build_wonder_button_label(char* buf, int bufsize,
                                               bool* help_build_possible)
{
  struct city* destcity = game_find_city_by_number(caravan_city_id);
  struct unit* caravan = game_find_unit_by_number(caravan_unit_id);
  
  if (destcity && caravan
      && unit_can_help_build_wonder(caravan, destcity)) {
    my_snprintf(buf, bufsize, _("Help build _Wonder (%d remaining)"),
	impr_build_shield_cost(destcity->production.value.building)
	- destcity->shield_stock);
    *help_build_possible = TRUE;
  } else {
    my_snprintf(buf, bufsize, _("Help build _Wonder"));
    *help_build_possible = FALSE;
  }
}
Example #5
0
/**************************************************************************
  Callack for when user clicks one of the unit icons on left hand side
  (units on same square as current unit).  Use unit_ids[] data and change
  focus to clicked unit.
**************************************************************************/
static void unit_icon_callback(Widget w, XtPointer client_data,
			       XtPointer call_data) 
{
  struct unit *punit;
  int i = (size_t)client_data;

  assert(i>=0 && i<num_units_below);
  if (unit_ids[i] == 0) /* no unit displayed at this place */
    return;
  punit=game_find_unit_by_number(unit_ids[i]);
  if(punit) { /* should always be true at this point */
    if (unit_owner(punit) == client.conn.playing) {
      /* may be non-true if alliance */
      set_unit_focus(punit);
    }
  }
}