Exemple #1
0
/****************************************************************************
  Returns a bit vector of the roads present at the tile.
****************************************************************************/
bv_roads tile_roads(const struct tile *ptile)
{
  if (!ptile) {
    bv_roads empty;
    BV_CLR_ALL(empty);
    return empty;
  }
#if 0
  /* TODO: Use this when tile roads vector always has correct information.
   *       For now we have to construct vector by checking each road separately. */
  return ptile->roads;
#else
  {
    bv_roads roads;
    BV_CLR_ALL(roads);
    road_type_iterate(proad) {
      if (tile_has_road(ptile, proad)) {
        BV_SET(roads, road_index(proad));
      }
    } road_type_iterate_end;

    return roads;
  }
#endif
}
Exemple #2
0
/**************************************************************************
  Initialise the unit data from the ruleset for the advisors.
**************************************************************************/
void adv_units_ruleset_init(void)
{
  bv_special special;
  bv_bases bases;
  bv_roads roads;

  BV_CLR_ALL(special);
  BV_CLR_ALL(bases);
  BV_CLR_ALL(roads); /* Can it move even without road */

  unit_class_iterate(pclass) {
    bool move_land_enabled  = FALSE; /* Can move at some land terrains */
    bool move_land_disabled = FALSE; /* Cannot move at some land terrains */
    bool move_sea_enabled   = FALSE; /* Can move at some ocean terrains */
    bool move_sea_disabled  = FALSE; /* Cannot move at some ocean terrains */

    terrain_type_iterate(pterrain) {
      if (is_native_to_class(pclass, pterrain, special, bases, roads)) {
        /* Can move at terrain */
        if (is_ocean(pterrain)) {
          move_sea_enabled = TRUE;
        } else {
          move_land_enabled = TRUE;
        }
      } else {
        /* Cannot move at terrain */
        if (is_ocean(pterrain)) {
          move_sea_disabled = TRUE;
        } else {
          move_land_disabled = TRUE;
        }
      }
    } terrain_type_iterate_end;

    if (move_land_enabled && !move_land_disabled) {
      pclass->adv.land_move = MOVE_FULL;
    } else if (move_land_enabled && move_land_disabled) {
      pclass->adv.land_move = MOVE_PARTIAL;
    } else {
      fc_assert(!move_land_enabled);
      pclass->adv.land_move = MOVE_NONE;
    }

    if (move_sea_enabled && !move_sea_disabled) {
      pclass->adv.sea_move = MOVE_FULL;
    } else if (move_sea_enabled && move_sea_disabled) {
      pclass->adv.sea_move = MOVE_PARTIAL;
    } else {
      fc_assert(!move_sea_enabled);
      pclass->adv.sea_move = MOVE_NONE;
    }

  } unit_class_iterate_end;
}
Exemple #3
0
/****************************************************************************
  Returns a bit vector of the bases present at the tile.
****************************************************************************/
bv_bases tile_bases(const struct tile *ptile)
{
  if (!ptile) {
    bv_bases empty;
    BV_CLR_ALL(empty);
    return empty;
  }
  return ptile->bases;
}
Exemple #4
0
/****************************************************************************
  Returns a bit vector of the extras present at the tile.
****************************************************************************/
bv_extras tile_extras(const struct tile *ptile)
{
  if (!ptile) {
    bv_extras empty;

    BV_CLR_ALL(empty);
    return empty;
  }

  return ptile->extras;
}
Exemple #5
0
/**************************************************************************
  Updates required_techs, num_required_techs and bulbs_required in
  pplayer->research->inventions[goal].
**************************************************************************/
static void build_required_techs(struct player *pplayer, Tech_type_id goal)
{
  int counter;
  struct player_research *research = player_research_get(pplayer);

  BV_CLR_ALL(research->inventions[goal].required_techs);
  
  if (player_invention_state(pplayer, goal) == TECH_KNOWN) {
    research->inventions[goal].num_required_techs = 0;
    research->inventions[goal].bulbs_required = 0;
    return;
  }
  
  build_required_techs_helper(pplayer, goal, goal);

  /* Include the goal tech */
  research->inventions[goal].bulbs_required =
      base_total_bulbs_required(pplayer, goal);
  research->inventions[goal].num_required_techs = 1;

  counter = 0;
  advance_index_iterate(A_FIRST, i) {
    if (!is_tech_a_req_for_goal(pplayer, i, goal)) {
      continue;
    }

    /* 
     * This is needed to get a correct result for the
     * base_total_bulbs_required call.
     */
    research->techs_researched++;
    counter++;

    research->inventions[goal].num_required_techs++;
    research->inventions[goal].bulbs_required +=
	base_total_bulbs_required(pplayer, i);
  } advance_index_iterate_end;

  /* Undo the changes made above */
  research->techs_researched -= counter;
}
Exemple #6
0
/**************************************************************************
  Popup a dialog asking the unit which improvement they would like to
  pillage.
**************************************************************************/
void popup_pillage_dialog(struct unit *punit,
			  bv_special spe,
                          bv_bases bases,
                          bv_roads roads)
{
  Widget shell, form, dlabel, button, prev;
  struct act_tgt tgt;

  if (is_showing_pillage_dialog) {
    return;
  }
  is_showing_pillage_dialog = TRUE;
  unit_to_use_to_pillage = punit->id;

  XtSetSensitive (toplevel, FALSE);

  shell = I_T(XtCreatePopupShell("pillagedialog", transientShellWidgetClass,
				 toplevel, NULL, 0));
  form = XtVaCreateManagedWidget ("form", formWidgetClass, shell, NULL);
  dlabel = I_L(XtVaCreateManagedWidget("dlabel", labelWidgetClass, form, NULL));

  prev = dlabel;
  while (get_preferred_pillage(&tgt, spe, bases, roads)) {
    bv_special what_spe;
    bv_bases what_base;
    bv_roads what_road;
    int what = S_LAST;

    BV_CLR_ALL(what_spe);
    BV_CLR_ALL(what_base);
    BV_CLR_ALL(what_road);

    switch (tgt.type) {
      case ATT_SPECIAL:
        BV_SET(what_spe, tgt.obj.spe);
        what = tgt.obj.spe;
        clear_special(&spe, tgt.obj.spe);
        break;
      case ATT_BASE:
        BV_SET(what_base, tgt.obj.base);
        what = tgt.obj.base + S_LAST;
        BV_CLR(bases, tgt.obj.base);
        break;
      case ATT_ROAD:
        BV_SET(what_road, tgt.obj.road);
        what = tgt.obj.road + S_LAST + game.control.num_base_types;
        BV_CLR(roads, tgt.obj.road);
        break;
    }

    button =
      XtVaCreateManagedWidget ("button", commandWidgetClass, form,
                               XtNfromVert, prev,
                               XtNlabel,
                               (XtArgVal)(get_infrastructure_text(what_spe,
                                                                  what_base,
                                                                  what_road)),
                               NULL);
    XtAddCallback(button, XtNcallback, pillage_callback,
                  INT_TO_XTPOINTER(what));

    prev = button;
  }
  button =
    I_L(XtVaCreateManagedWidget("closebutton", commandWidgetClass, form,
				XtNfromVert, prev,
				NULL));
  XtAddCallback (button, XtNcallback, pillage_callback, NULL);

  xaw_set_relative_position (toplevel, shell, 10, 0);
  XtPopup (shell, XtGrabNone);
}