/**
 * @brief Fills the fields from the existing entity.
 */
void EditEntityDialog::initialize() {

  initialize_simple_booleans();
  initialize_simple_integers();
  initialize_simple_strings();

  initialize_behavior();
  initialize_breed();
  initialize_damage_on_enemies();
  initialize_destination();
  initialize_destination_map();
  initialize_direction();
  initialize_font();
  initialize_ground();
  initialize_layer();
  initialize_maximum_moves();
  initialize_model();
  initialize_name();
  initialize_opening_method();
  initialize_rank();
  initialize_savegame_variable();
  initialize_size();
  initialize_sound();
  initialize_sprite();
  initialize_subtype();
  initialize_transition();
  initialize_treasure();
  initialize_type();
  initialize_weight();
  initialize_xy();

  adjustSize();
}
Beispiel #2
0
/**
 * @brief Creates a new chest with the specified treasure.
 * @param name name identifying this chest
 * @param layer layer of the chest to create on the map
 * @param x x coordinate of the chest to create
 * @param y y coordinate of the chest to create
 * @param big_chest true to make a big chest, false to make a normal chest
 * @param treasure the treasure in the chest (will be deleted automatically)
 */
Chest::Chest(const std::string &name, Layer layer, int x, int y,
	     bool big_chest, const Treasure &treasure):

  Detector(COLLISION_FACING_POINT, name, layer, x, y, 16, 16),
  treasure(treasure),
  big_chest(big_chest),
  open(treasure.is_found()),
  treasure_given(open),
  treasure_date(0) {

  initialize_sprite();
}
Beispiel #3
0
/**
 * \brief Creates an NPC.
 * \param game the game
 * \param name name identifying this NPC
 * \param layer layer of the entity to create
 * \param xy Coordinates of the entity to create.
 * \param subtype the subtype of interaction
 * \param sprite_name sprite animation set of the entity, or an empty string to create no sprite
 * \param direction for a generalized NPC: direction for which the interactions are allowed
 * (0 to 4, or -1 for any direction), for a usual NPC: initial direction of the NPC's sprite
 * \param behavior_string indicates what happens when the hero interacts with this NPC:
 * "dialog#XXX" to start the dialog XXX, "map" to call the map script
 * (with an event_hero_interaction() call) or "item#XXX" to call the script
 * of item XXX  (with an event_hero_interaction() call)
 */
Npc::Npc(
    Game& /* game */,
    const std::string& name,
    int layer,
    const Point& xy,
    Subtype subtype,
    const std::string& sprite_name,
    int direction,
    const std::string& behavior_string
):
  Entity(name, 0, layer, xy, Size(0, 0)),
  subtype(subtype),
  behavior(BEHAVIOR_MAP_SCRIPT),
  traversable(false),
  dialog_to_show(""),
  item_name("") {

  set_collision_modes(CollisionMode::COLLISION_FACING | CollisionMode::COLLISION_OVERLAPPING);
  initialize_sprite(sprite_name, direction);
  set_size(16, 16);
  set_origin(8, 13);
  set_direction(direction);

  // Usual NPCs are displayed like the hero whereas generalized NPCs are
  // not necessarily people.
  set_drawn_in_y_order(subtype == USUAL_NPC);

  // behavior
  if (behavior_string == "map") {
    behavior = BEHAVIOR_MAP_SCRIPT;
  }
  else if (behavior_string.substr(0, 5) == "item#") {
    behavior = BEHAVIOR_ITEM_SCRIPT;
    item_name = behavior_string.substr(5);
  }
  else if (behavior_string.substr(0, 7) == "dialog#") {
    behavior = BEHAVIOR_DIALOG;
    dialog_to_show = behavior_string.substr(7);
  }
  else {
    Debug::die(std::string("Invalid behavior string for NPC '") + name
        + "': '" + behavior_string + "'");
  }
}
Beispiel #4
0
int SpriteCache::loadSprite(int index)
{

  int hh = 0;

  while (cachesize > maxCacheSize) {
    removeOldest();
    hh++;
    if (hh > 1000) {
      write_log("!!!! RUNTIME CACHE ERROR: STUCK IN FREE_UP_MEM; RESETTING CACHE");
      removeAll();
    }

  }

  if ((index < 0) || (index >= elements))
    quit("sprite cache array index out of bounds");

  // If we didn't just load the previous sprite, seek to it
  seekToSprite(index);

  int coldep = getshort(ff);

  if (coldep == 0) {
    lastLoad = index;
    return 0;
  }

  int wdd = getshort(ff);
  int htt = getshort(ff);
  // update the stored width/height
  spritewidth[index] = wdd;
  spriteheight[index] = htt;

  images[index] = create_bitmap_ex(coldep * 8, wdd, htt);
  if (images[index] == NULL) {
    offsets[index] = 0;
    return 0;
  }

  if (this->spritesAreCompressed) 
  {
    getw(ff); // skip data size
    if (coldep == 1) {
      for (hh = 0; hh < htt; hh++)
        cunpackbitl(&images[index]->line[hh][0], wdd, ff);
    }
    else if (coldep == 2) {
      for (hh = 0; hh < htt; hh++)
        cunpackbitl16((unsigned short*)&images[index]->line[hh][0], wdd, ff);
    }
    else {
      for (hh = 0; hh < htt; hh++)
        cunpackbitl32((unsigned long*)&images[index]->line[hh][0], wdd, ff);
    }
  }
  else {
    for (hh = 0; hh < htt; hh++)
      // MACPORT FIX: size and nmemb split
      fread(&images[index]->line[hh][0], coldep, wdd, ff);
  }

  lastLoad = index;

  // Stop it adding the sprite to the used list just because it's loaded
  long offs = offsets[index];
  offsets[index] = SPRITE_LOCKED;

  initialize_sprite(index);

  if (index != 0)  // leave sprite 0 locked
    offsets[index] = offs;

  // we need to store this because the main program might
  // alter spritewidth/height if it resizes stuff
  sizes[index] = spritewidth[index] * spriteheight[index] * coldep;
  cachesize += sizes[index];

#ifdef DEBUG_SPRITECACHE
  char msgg[100];
  sprintf(msgg, "Loaded %d, size now %d KB", index, cachesize / 1024);
  write_log(msgg);
#endif

  return sizes[index];
}