~ubuntu-branches/debian/sid/freeciv/sid

« back to all changes in this revision

Viewing changes to common/tile.c

  • Committer: Package Import Robot
  • Author(s): Karl Goetz
  • Date: 2011-12-31 11:39:58 UTC
  • mfrom: (1.2.20)
  • Revision ID: package-import@ubuntu.com-20111231113958-laureotb00yk2331
Tags: 2.3.1-1
* Switch to short style dh with overrides
  - Update control to 7.0.50 and compat to 7
  - Various packaging cleanups, fixes various issues with our
    packaging that appears to have been broken for some time.
* Change our dependency away from ttf-sazanami-gothic per the
  request of its maintainer (Closes: #642944)
* New package freeciv-client-extras with freeciv-modpack in it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
****************************************************************************/
118
118
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
119
119
{
 
120
  /* The terrain change is valid if one of the following is TRUE:
 
121
   * - pterrain is NULL (= unknown terrain)
 
122
   * - ptile is a virtual tile
 
123
   * - pterrain does not has the flag TER_NO_CITIES
 
124
   * - there is no city on ptile.
 
125
   * This should be read as: The terrain change is INVALID if a terrain with
 
126
   * the flag TER_NO_CITIES is given for a real tile with a city (i.e. all
 
127
   * check evaluate to TRUE). */
120
128
  fc_assert_msg(NULL == pterrain
 
129
                || tile_virtual_check(ptile)
121
130
                || !terrain_has_flag(pterrain, TER_NO_CITIES)
122
131
                || NULL == tile_city(ptile),
123
132
                "At (%d, %d), the terrain \"%s\" (nb %d) doesn't "
440
449
/****************************************************************************
441
450
  Clear all infrastructure (man-made specials) from the tile.
442
451
****************************************************************************/
443
 
static void tile_clear_infrastructure(struct tile *ptile)
 
452
static void tile_clear_unsupported_infrastructure(struct tile *ptile)
444
453
{
445
454
  int i;
 
455
  bool city_present = tile_city(ptile) != NULL;
 
456
  struct terrain *pterr = tile_terrain(ptile);
 
457
  bool ocean = is_ocean(pterr);
446
458
 
447
459
  for (i = 0; infrastructure_specials[i] != S_LAST; i++) {
448
 
    tile_clear_special(ptile, infrastructure_specials[i]);
 
460
    switch (infrastructure_specials[i]) {
 
461
    case S_ROAD:
 
462
    case S_RAILROAD:
 
463
      if (!city_present && pterr->road_time == 0) {
 
464
        tile_clear_special(ptile, infrastructure_specials[i]);
 
465
      }
 
466
      break;
 
467
    default:
 
468
      if (ocean) {
 
469
        tile_clear_special(ptile, infrastructure_specials[i]);
 
470
      }
 
471
      break;
 
472
    }
449
473
  }
450
474
}
451
475
 
466
490
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
467
491
{
468
492
  tile_set_terrain(ptile, pterrain);
 
493
  tile_clear_unsupported_infrastructure(ptile);
 
494
 
469
495
  if (is_ocean(pterrain)) {
470
 
    tile_clear_infrastructure(ptile);
471
 
 
472
496
    /* The code can't handle these specials in ocean. */
473
497
    tile_clear_special(ptile, S_RIVER);
474
498
    tile_clear_special(ptile, S_HUT);
493
517
  base_type_iterate(pbase) {
494
518
    if (tile_has_base(ptile, pbase)
495
519
        && !is_native_tile_to_base(pbase, ptile)) {
 
520
      if (fc_funcs->destroy_base != NULL) {
 
521
        fc_funcs->destroy_base(ptile, pbase);
 
522
      } else {
 
523
        tile_remove_base(ptile, pbase);
 
524
      }
496
525
      tile_remove_base(ptile, pbase);
497
526
    }
498
527
  } base_type_iterate_end;
818
847
  vtile->spec_sprite = NULL;
819
848
 
820
849
  if (ptile) {
 
850
    /* Used by is_city_center to give virtual tiles the output bonuses
 
851
     * they deserve */
 
852
    vtile->x = ptile->x;
 
853
    vtile->y = ptile->y;
 
854
 
821
855
    /* Copy all but the unit list. */
822
856
    tile_special_type_iterate(spe) {
823
857
      if (BV_ISSET(ptile->special, spe)) {
825
859
      }
826
860
    } tile_special_type_iterate_end;
827
861
 
 
862
    if (BV_ISSET(ptile->special, S_RESOURCE_VALID)) {
 
863
      BV_SET(vtile->special, S_RESOURCE_VALID);
 
864
    }
 
865
 
828
866
    base_type_iterate(pbase) {
829
867
      if (BV_ISSET(ptile->bases, base_number(pbase))) {
830
868
        BV_SET(vtile->bases, base_number(pbase));
877
915
 
878
916
  free(vtile);
879
917
}
 
918
 
 
919
/****************************************************************************
 
920
  Check if the given tile is a virtual one or not.
 
921
****************************************************************************/
 
922
bool tile_virtual_check(struct tile *vtile)
 
923
{
 
924
  int tindex;
 
925
 
 
926
  if (!vtile || map_is_empty()) {
 
927
    return FALSE;
 
928
  }
 
929
 
 
930
  tindex = tile_index(vtile);
 
931
 
 
932
  if (tindex == -1) {
 
933
    /* This is a virtual tile. */
 
934
    return TRUE;
 
935
  }
 
936
 
 
937
  fc_assert_ret_val(0 <= tindex && tindex < map_num_tiles(), FALSE);
 
938
 
 
939
  return (vtile != map.tiles + tindex);
 
940
}
 
941
 
 
942
/****************************************************************************
 
943
  Returns key that should be used when storing tile to hash or when
 
944
  retrieving it from there.
 
945
****************************************************************************/
 
946
void *tile_hash_key(const struct tile *ptile)
 
947
{
 
948
  void *key = 0; /* Initialize whole sizeof(void *) */
 
949
 
 
950
  key = FC_INT_TO_PTR(ptile->index);
 
951
 
 
952
  return key;
 
953
}