示例#1
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);
}
示例#2
0
void drawstimuli(Map m, Sensor s) {
  TCOD_list_t stims = sensor_consume_stimuli(s);
  unsigned char *tiles;
  mapVec pos, size, oldPt, delta;
  unsigned char visflags;
  if(TCOD_list_size(stims) > 0) {
    TCOD_console_print_left(NULL, 0, 10, TCOD_BKGND_NONE, "                            ");
  }
  for(int i = 0; i < TCOD_list_size(stims); i++) {
    //this is a very naive approach that completely ignores the possibility of overdraw and 'forgets' object positions
    Stimulus st = TCOD_list_get(stims, i);
    stimtype type = stimulus_type(st);
    TCOD_console_print_left(NULL, i*2, 10, TCOD_BKGND_NONE, "s%i", type);
    switch(type) {
      case StimTileLitChange:
      case StimTileVisChange:
        //redraw all tiles
        tiles = stimulus_tile_sight_change_get_new_tiles(st);
        pos = stimulus_tile_sight_change_get_position(st);
        size = stimulus_tile_sight_change_get_size(st);
        drawtiles(m, tiles, s, pos, size);
        break;
      case StimObjLitChange:
      case StimObjVisChange:
        //redraw object
        draw_object(st);
        break;
      case StimObjMoved:
        visflags = stimulus_obj_sight_change_get_new_flags(st);
        pos = stimulus_obj_sight_change_get_position(st);
        delta = stimulus_obj_moved_get_dir(st);
        oldPt = mapvec_subtract(pos, delta);
        TCOD_console_print_left(NULL, oldPt.x*2, oldPt.y, TCOD_BKGND_NONE, "x");
        draw_object(st);
        TCOD_console_print_left(NULL, 0, 15, TCOD_BKGND_NONE, "got move");
        break;
      case StimGeneric:
      default:
        TCOD_console_print_left(NULL, i*9, 16, TCOD_BKGND_NONE, "generic %d", i);
        break;
    }
    stimulus_free(st);
  }
  TCOD_list_delete(stims);
}