Exemple #1
0
/**************************************************************************
...
**************************************************************************/
static void sha_tile_update(struct tile *ptile)
{
  freelog(LOG_DEBUG, "sha got tile: %d ~= (%d, %d)",
	  tile_index(ptile), TILE_XY(ptile));

#if 0
  previous_tiles[tile_index(ptile)] = *ptile;
#endif
}
Exemple #2
0
void sensor_push_stimulus(Sensor s, Stimulus stim) {
  mapVec pt, sz;
  perception *newVis;
  perception *snewVis = s->vistiles;
  perception newPerception;
  bool litAndVisible;
  Object o;
  Map m = s->map;
  mapVec borig=s->borig, bsz=s->bsz;
  switch(stimulus_type(stim)) {
    case StimTileLitChange:
    case StimTileVisChange:
      newVis = stimulus_tile_sight_change_get_new_perceptmap(stim);
      pt = stimulus_tile_sight_change_get_position(stim);
      sz = stimulus_tile_sight_change_get_size(stim);
      for(int z = pt.z; z < pt.z+sz.z; z++) {
        for(int y = pt.y; y < pt.y+sz.y; y++) {
          for(int x = pt.x; x < pt.x+sz.x; x++) {
            int stimIndex = tile_index(x, y, z, map_size(m), pt, sz);
            int visIndex = tile_index(x, y, z, map_size(m), borig, bsz);
            snewVis[visIndex] = newVis[stimIndex];
          }
        }
      }
      break;
    case StimObjLitChange:
    case StimObjVisChange:
    case StimObjMoved:
      //is the object in newVis? if so, put it into oldVis; if not, make sure it isn't in oldVis.
      //do this search by _ID_, not by identity
      //are the new flags good? if so, be sure the object is in vis. otherwise, be sure it's not in vis.
      if(sensor_visobjs_contains(s->visObjects, o)) {
        sensor_visobjs_push(s->oldVisObjects, o);
      } else {
        sensor_visobjs_remove(s->oldVisObjects, o);
      }
      newPerception = stimulus_obj_sight_change_get_new_perception(stim);
      litAndVisible = map_item_visible(newPerception);
      
      if(litAndVisible) {
        if(!sensor_visobjs_contains(s->visObjects, o)) {
          sensor_visobjs_push(s->visObjects, o);
        }
      } else {
        if(sensor_visobjs_contains(s->visObjects, o)) {
          sensor_visobjs_remove(s->visObjects, o);
        }
      }
      break;
    case StimGeneric:
    default:
      break;
  }
  TCOD_list_push(s->stimuli, stim);
}
Exemple #3
0
/****************************************************************************
  Send the needed packets for connections entering in the editing mode.
****************************************************************************/
void edithand_send_initial_packets(struct conn_list *dest)
{
  struct packet_edit_startpos startpos;
  struct packet_edit_startpos_full startpos_full;

  if (NULL == dest) {
    dest = game.est_connections;
  }

  /* Send map start positions. */
  map_startpos_iterate(psp) {
    startpos.id = tile_index(startpos_tile(psp));
    startpos.remove = FALSE;
    startpos.tag = 0;

    startpos_pack(psp, &startpos_full);

    conn_list_iterate(dest, pconn) {
      if (can_conn_edit(pconn)) {
        send_packet_edit_startpos(pconn, &startpos);
        send_packet_edit_startpos_full(pconn, &startpos_full);
      }
    } conn_list_iterate_end;
  } map_startpos_iterate_end;
}
Exemple #4
0
/**************************************************************************
 Popup dialog where the user choose the name of the new city
 punit = (settler) unit which builds the city
 suggestname = suggetion of the new city's name
**************************************************************************/
void popup_newcity_dialog(struct unit *punit, const char *suggestname)
{
  input_dialog_create(GTK_WINDOW(toplevel), /*"shellnewcityname" */
                      _("Build New City"),
                      _("What should we call our new city?"), suggestname,
                      name_new_city_popup_callback,
                      GINT_TO_POINTER(tile_index(unit_tile(punit))));
}
Exemple #5
0
void drawtiles(Map m, unsigned char *buf, Sensor s, mapVec pos, mapVec size) {
  int index=0;
  unsigned char tileIndex;
  unsigned char flags;
  int drawX, drawY;
  Volume vol = sensor_volume(s);
  mapVec borig, bsz;
  volume_swept_bounds(vol, &borig, &bsz);
  mapVec msz = map_size(m);
  float ystart = CLIP(pos.y, 0, msz.y);
  float xstart = CLIP(pos.x, 0, msz.x);
  float yend = CLIP(pos.y+size.y, 0, msz.y);
  float xend = CLIP(pos.x+size.x, 0, msz.x);
  int z = CLIP(pos.z, 0, msz.z); //note: different from test.c version
  for(int y = ystart; y < yend; y++) {
    for(int x = xstart; x < xend; x++) {
      index = tile_index(x, y, z, msz, borig, bsz);
      flags = buf[index];
      TCOD_console_print_left(NULL, 0, 18, TCOD_BKGND_NONE, "%i, %i, %i", map_item_lit(flags), map_item_in_volume(flags), map_item_los(flags));
      tileIndex = map_tile_at(m, x, y, z);
      drawX = x*2+z*((msz.x*2)+1);
      drawY = y;
      //TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "%i", index);
      if(map_item_visible(flags)) {
         //visible and lit and in volume
         TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "%i", tileIndex);
      }
      // else if(!map_item_lit(flags) && map_item_in_volume(flags) && map_item_los(flags)) {
      //   //not lit and viewable
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "_");
      // }
      // else if(!map_item_lit(flags) && map_item_in_volume(flags) && !map_item_los(flags)) {
      //   //not lit and not los
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, ",");
      // }
      // else if(!map_item_lit(flags) && !map_item_in_volume(flags) && map_item_los(flags)) {
      //   //not lit and not in vol
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "d");
      // }
      // else if(map_item_lit(flags) && !map_item_in_volume(flags) && map_item_los(flags)) {
      //   //lit and in los, but not in vol
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "a");
      // }
      // else if(map_item_lit(flags) && map_item_in_volume(flags) && !map_item_los(flags)) {
      //   //lit and in vol, but not in los
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "b");
      // }
      // else if(map_item_lit(flags) && !map_item_in_volume(flags) && !map_item_los(flags)) {
      //   //lit and not in vol or los (or los wasn't checked)
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, ".");
      // }
      // else if(!map_item_lit(flags) && !map_item_in_volume(flags) && !map_item_los(flags)) { 
      //   //not lit, in vol, or in los
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "x");
      // }
    }
  }
}
Exemple #6
0
/**************************************************************************
  Main handler for mouse movement handling.
**************************************************************************/
static Uint16 main_mouse_motion_handler(SDL_MouseMotionEvent *pMotionEvent, void *pData)
{
    static struct widget *pWidget;
    struct tile *ptile;

    /* stop evaluating button hold time when moving to another tile in medium
     * hold state or above */
    if (button_behavior.counting && (button_behavior.hold_state >= MB_HOLD_MEDIUM)) {
        ptile = canvas_pos_to_tile(pMotionEvent->x, pMotionEvent->y);
        if (tile_index(ptile) != tile_index(button_behavior.ptile)) {
            button_behavior.counting = FALSE;
        }
    }

    if(draw_goto_patrol_lines) {
        update_line(pMotionEvent->x, pMotionEvent->y);
    }

#ifndef UNDER_CE
    if (gui_sdl_fullscreen) {
        check_scroll_area(pMotionEvent->x, pMotionEvent->y);
    }
#endif /* UNDER_CE */

    if ((pWidget = find_next_widget_at_pos(NULL,
                                           pMotionEvent->x,
                                           pMotionEvent->y)) != NULL) {
        update_mouse_cursor(CURSOR_DEFAULT);
        if (!(get_wstate(pWidget) == FC_WS_DISABLED)) {
            widget_sellected_action(pWidget);
        }
    } else {
        if (pSellected_Widget) {
            unsellect_widget_action();
        } else {
            control_mouse_cursor(canvas_pos_to_tile(pMotionEvent->x, pMotionEvent->y));
        }
    }

    draw_mouse_cursor();

    return ID_ERROR;
}
Exemple #7
0
//------------------------------------------------------------------------------
void
Background2D::load( const QGears::Background2DFile::TileList& tiles )
{
    QGears::Background2DFile::TileList::const_iterator it( tiles.begin() );
    QGears::Background2DFile::TileList::const_iterator it_end( tiles.end() );
    size_t tile_index( 0 );
    while( it != it_end )
    {
        AddTile( *it );
        load( tile_index++, it->animations );
        ++it;
    }
}
Exemple #8
0
void sensor_sense(Sensor s) {
  Map m = s->map;
  
  mapVec pos=s->borig, sz=s->bsz;
  memset(s->vistiles, 0, sz.x*sz.y*sz.z*sizeof(perception));
  map_get_visible_tiles(m, s->vistiles, s->volume, pos, sz);
  Stimulus vistiles = stimulus_init_tile_vis_change(stimulus_new(), s->vistiles, pos, sz);
  // TCOD_console_print_left(NULL, 0, 20, "p {%f, %f, %f}, s {%f, %f, %f}", pos.x, pos.y, pos.z, sz.x, sz.y, sz.z);
  
  TCOD_list_push(s->stimuli, vistiles);
  
  TCOD_list_t oldObjList = s->visObjects; //one ago
  s->visObjects = s->oldVisObjects; //two ago
  TCOD_list_clear(s->visObjects);
  s->oldVisObjects = oldObjList;
  
  map_get_visible_objects(m, s->visObjects, s->vistiles, pos, sz);
  //remove the old objects
  Object o;
  mapVec pt;
  int index;
  Stimulus visobj;
  for(int i = 0; i < TCOD_list_size(s->oldVisObjects); i++) {
    o = TCOD_list_get(s->oldVisObjects, i);
    if(!TCOD_list_contains(s->visObjects, o)) { //not visible anymore
      //this isn't quite right, really, using percept_none here
      visobj = stimulus_init_obj_vis_change(stimulus_new(), o, percept_none, object_context(o));
      TCOD_list_push(s->stimuli, visobj);
    }
  }
  //add the new objects
  for(int i = 0; i < TCOD_list_size(s->visObjects); i++) {
    o = TCOD_list_get(s->visObjects, i);
    if(!TCOD_list_contains(s->oldVisObjects, o)) { //not visible before
      pt = object_position(o);
      index = tile_index(pt.x, pt.y, pt.z, map_size(m), pos, sz);
      visobj = stimulus_init_obj_vis_change(stimulus_new(), o, s->vistiles[index], object_context(o));
      TCOD_list_push(s->stimuli, visobj);
    }
  }
}
Exemple #9
0
/***************************************************************************
  Client variant of city_tile().  This include the case of this could a
  ghost city (see client/packhand.c).  In a such case, the returned tile
  is an approximative position of the city on the map.
***************************************************************************/
struct tile *client_city_tile(const struct city *pcity)
{
  int dx, dy;
  double x = 0, y = 0;
  size_t num = 0;

  if (NULL == pcity) {
    return NULL;
  }

  if (NULL != city_tile(pcity)) {
    /* Normal city case. */
    return city_tile(pcity);
  }

  whole_map_iterate(ptile) {
    int tile_x, tile_y;

    index_to_map_pos(&tile_x, &tile_y, tile_index(ptile));
    if (pcity == tile_worked(ptile)) {
      if (0 == num) {
        x = tile_x;
        y = tile_y;
        num = 1;
      } else {
        num++;
        base_map_distance_vector(&dx, &dy, (int)x, (int)y, tile_x, tile_y);
        x += (double) dx / num;
        y += (double) dy / num;
      }
    }
  } whole_map_iterate_end;

  if (0 < num) {
    return map_pos_to_tile((int) x, (int) y);
  } else {
    return NULL;
  }
}
Exemple #10
0
/**************************************************************************
  Log unit messages, they will appear like this
    2: Polish Archers[139] (5,35)->(0,0){0,0} stays to defend city
  where [] is unit id, ()->() are coordinates present and goto, and
  {,} contains bodyguard and ferryboat ids.
**************************************************************************/
void real_unit_log(const char *file, const char *function, int line,
                   enum log_level level,  bool notify,
                   const struct unit *punit, const char *msg, ...)
{
  char buffer[500];
  char buffer2[500];
  va_list ap;
  int gx, gy;
  char aibuf[500] = "\0";

  CALL_PLR_AI_FUNC(log_fragment_unit, unit_owner(punit), aibuf, sizeof(aibuf), punit);

  if (punit->goto_tile) {
    index_to_map_pos(&gx, &gy, tile_index(punit->goto_tile));
  } else {
    gx = gy = -1;
  }

  fc_snprintf(buffer, sizeof(buffer),
	      "%s %s[%d] %s (%d,%d)->(%d,%d){%s} ",
              nation_rule_name(nation_of_unit(punit)),
              unit_rule_name(punit),
              punit->id,
	      get_activity_text(punit->activity),
	      TILE_XY(unit_tile(punit)),
	      gx, gy, aibuf);

  va_start(ap, msg);
  fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap);
  va_end(ap);

  cat_snprintf(buffer, sizeof(buffer), "%s", buffer2);
  if (notify) {
    notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer);
  }
  do_log(file, function, line, FALSE, level, "%s", buffer);
}
Exemple #11
0
/**************************************************************************
...
**************************************************************************/
struct tile *sha_tile_recall(struct tile *ptile)
{
  return &previous_tiles[tile_index(ptile)];
}