/**
 * Loads map file with given level number and file extension.
 * @return Returns NULL if the file doesn't exist or is smaller than ldsize;
 * on success, returns a buffer which should be freed after use,
 * and sets ldsize into its size.
 */
unsigned char *load_single_map_file_to_buffer(LevelNumber lvnum,const char *fext,long *ldsize,unsigned short flags)
{
  unsigned char *buf;
  char *fname;
  long fsize;
  short fgroup;
  fgroup = get_level_fgroup(lvnum);
  fname = prepare_file_fmtpath(fgroup,"map%05lu.%s",lvnum,fext);
  wait_for_cd_to_be_available();
  fsize = LbFileLengthRnc(fname);
  if (fsize < *ldsize)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Map file \"map%05lu.%s\" doesn't exist or is too small.",lvnum,fext);
    else
      SYNCMSG("Optional file \"map%05lu.%s\" doesn't exist or is too small.",lvnum,fext);
    return NULL;
  }
  if (fsize > ANY_MAP_FILE_MAX_SIZE)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Map file \"map%05lu.%s\" exceeds max size of %d; loading failed.",lvnum,fext,ANY_MAP_FILE_MAX_SIZE);
    else
      SYNCMSG("Optional file \"map%05lu.%s\" exceeds max size of %d; not loading.",lvnum,fext,ANY_MAP_FILE_MAX_SIZE);
    return NULL;
  }
  buf = LbMemoryAlloc(fsize+16);
  if (buf == NULL)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Can't allocate %ld bytes to load \"map%05lu.%s\".",fsize,lvnum,fext);
    else
      SYNCMSG("Can't allocate %ld bytes to load \"map%05lu.%s\".",fsize,lvnum,fext);
    return NULL;
  }
  fsize = LbFileLoadAt(fname,buf);
  if (fsize < *ldsize)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Reading map file \"map%05lu.%s\" failed.",lvnum,fext);
    else
      SYNCMSG("Reading optional file \"map%05lu.%s\" failed.",lvnum,fext);
    LbMemoryFree(buf);
    return NULL;
  }
  *ldsize = fsize;
  SYNCDBG(7,"Map file \"map%05lu.%s\" loaded.",lvnum,fext);
  return buf;
}
示例#2
0
/**
 * Allocates graphics heap.
 */
TbBool setup_heap_memory(void)
{
  long i;
  SYNCDBG(8,"Starting");
  if (heap != NULL)
  {
    SYNCDBG(0,"Freeing old Graphics heap");
    LbMemoryFree(heap);
    heap = NULL;
  }
  i = mem_size;
  heap_size = get_best_sound_heap_size(i);
  while ( 1 )
  {
    heap = LbMemoryAlloc(heap_size);
    if (heap != NULL)
      break;
    i = get_smaller_memory_amount(i);
    if (i > 8)
    {
      heap_size = get_best_sound_heap_size(i);
    } else
    {
      if (heap_size < 524288)
      {
        ERRORLOG("Unable to allocate Graphic Heap");
        heap_size = 0;
        return false;
      }
      heap_size -= 16384;
    }
  }
  SYNCMSG("GraphicsHeap Size %d", heap_size);
  return true;
}
示例#3
0
TbBool show_onscreen_msg_va(int nturns, const char *fmt_str, va_list arg)
{
  vsprintf(onscreen_msg_text, fmt_str, arg);
  SYNCMSG("Onscreen message: %s",onscreen_msg_text);
  onscreen_msg_turns = nturns;
  return true;
}
TbBool initialise_map_wlb_auto(void)
{
    struct SlabMap *slb;
    struct SlabAttr *slbattr;
    unsigned long x,y;
    unsigned long n,nbridge;
    nbridge = 0;
    for (y=0; y < map_tiles_y; y++)
      for (x=0; x < map_tiles_x; x++)
      {
        slb = get_slabmap_block(x,y);
        if (slb->kind == SlbT_BRIDGE)
        {
          if (slabs_count_near(x,y,1,SlbT_LAVA) > slabs_count_near(x,y,1,SlbT_WATER))
            n = SlbT_LAVA;
          else
            n = SlbT_WATER;
          nbridge++;
        } else
        {
          n = slb->kind;
        }
        slbattr = get_slab_kind_attrs(n);
        n = (slbattr->wlb_type << 3);
        slb->field_5 ^= (slb->field_5 ^ n) & (0x10|0x08);
      }
    SYNCMSG("Regenerated WLB flags, unsure for %d bridge blocks.",(int)nbridge);
    return true;
}
示例#5
0
short setup_network_service(int srvidx)
{
  struct ServiceInitData *init_data;
  long maxplayrs;

  switch (srvidx)
  {
  case 0:
      maxplayrs = 2;
      init_data = &net_serial_data;
      set_flag_byte(&game.flags_font,FFlg_unk10,true);
      SYNCMSG("Initializing %d-players serial network",maxplayrs);
      break;
  case 1:
      maxplayrs = 2;
      init_data = &net_modem_data;
      set_flag_byte(&game.flags_font,FFlg_unk10,true);
      SYNCMSG("Initializing %d-players modem network",maxplayrs);
      break;
  case 2:
      maxplayrs = 4;
      init_data = NULL;
      set_flag_byte(&game.flags_font,FFlg_unk10,false);
      SYNCMSG("Initializing %d-players IPX network",maxplayrs);
      break;
  default:
      maxplayrs = 4;
      init_data = NULL;
      set_flag_byte(&game.flags_font,FFlg_unk10,false);
      SYNCMSG("Initializing %d-players type %d network",maxplayrs,srvidx);
      break;
  }
  LbMemorySet(&net_player_info[0], 0, sizeof(struct TbNetworkPlayerInfo));
  if ( LbNetwork_Init(srvidx, maxplayrs, &net_screen_packet,
      sizeof(struct ScreenPacket), &net_player_info[0], init_data) )
  {
    if (srvidx != 0)
      process_network_error(-800);
    return 0;
  }
  net_service_index_selected = srvidx;
  if ((game.flags_font & FFlg_unk10) != 0)
    LbNetwork_ChangeExchangeTimeout(10);
  frontend_set_state(FeSt_NET_SESSION);
  return 1;
}
示例#6
0
/**
 * Makes a bonus level for specified SP level visible on the land map screen.
 */
TbBool set_bonus_level_visibility_for_singleplayer_level(struct PlayerInfo *player, unsigned long sp_lvnum, short visible)
{
  long bn_lvnum;
  bn_lvnum = bonus_level_for_singleplayer_level(sp_lvnum);
  if (!set_bonus_level_visibility(bn_lvnum, visible))
  {
    if (visible)
      WARNMSG("Couldn't store bonus award for level %d",sp_lvnum);
    return false;
  }
  if (visible)
    SYNCMSG("Bonus award for level %d enabled",sp_lvnum);
  return true;
}
示例#7
0
TbBool setup_heaps(void)
{
    TbBool low_memory;
    char snd_fname[2048];
    char *spc_fname;
    long i;
    SYNCDBG(8,"Starting");
    low_memory = false;
    if (!SoundDisabled)
    {
      StopAllSamples();
      close_sound_heap();
      if (sound_heap_memory != NULL)
      {
        LbMemoryFree(sound_heap_memory);
        sound_heap_memory = NULL;
      }
    }
    if (heap != NULL)
    {
      ERRORLOG("Graphics heap already allocated");
      LbMemoryFree(heap);
      heap = NULL;
    }
    // Allocate sound heap
    if (!SoundDisabled)
    {
      i = mem_size;
      while (sound_heap_memory == NULL)
      {
        sound_heap_size = get_best_sound_heap_size(i);
        i = get_smaller_memory_amount(i);
        sound_heap_memory = LbMemoryAlloc(sound_heap_size);
        if ((i <= 8) && (sound_heap_memory == NULL))
        {
          low_memory = true;
          break;
        }
      }
    }
    // Allocate graphics heap
    i = mem_size;
    while (heap == NULL)
    {
      heap_size = get_best_sound_heap_size(i);
      i = get_smaller_memory_amount(i);
      heap = LbMemoryAlloc(heap_size);
      if ((i <= 8) && (heap == NULL))
      {
        low_memory = true;
        break;
      }
    }
    SYNCMSG("GraphicsHeap Size %d", heap_size);

    if (low_memory)
    {
      SYNCDBG(8,"Low memory mode entered on heap allocation.");
      while (heap != NULL)
      {
        if ((!SoundDisabled) && (sound_heap_memory == NULL))
        {
          break;
        }
        if (!SoundDisabled)
        {
          if (sound_heap_size < heap_size)
          {
            heap_size -= 16384;
          } else
          if (sound_heap_size == heap_size)
          {
            heap_size -= 16384;
            sound_heap_size -= 16384;
          } else
          {
            sound_heap_size -= 16384;
          }
          if (sound_heap_size < 524288)
          {
            ERRORLOG("Unable to allocate heaps (small_mem)");
            return false;
          }
        } else
        {
          heap_size -= 16384;
        }
        if (heap_size < 524288)
        {
          if (sound_heap_memory != NULL)
          {
            LbMemoryFree(sound_heap_memory);
            sound_heap_memory = NULL;
          }
          ERRORLOG("Unable to allocate heaps (small_mem)");
          return false;
          }
        }
        if (sound_heap_memory != NULL)
        {
          LbMemoryFree(sound_heap_memory);
          sound_heap_memory = NULL;
        }
        if (heap != NULL)
        {
          LbMemoryFree(heap);
          heap = NULL;
        }
        if (!SoundDisabled)
        {
          sound_heap_memory = LbMemoryAlloc(sound_heap_size);
        }
        heap = LbMemoryAlloc(heap_size);
    }
    if (!SoundDisabled)
    {
      SYNCMSG("SoundHeap Size %d", sound_heap_size);
      // Prepare sound sample bank file names
      prepare_file_path_buf(snd_fname,FGrp_LrgSound,sound_fname);
      // language-specific speech file
      spc_fname = prepare_file_fmtpath(FGrp_LrgSound,"speech_%s.dat",get_language_lwrstr(install_info.lang_id));
      // default speech file
      if (!LbFileExists(spc_fname))
        spc_fname = prepare_file_path(FGrp_LrgSound,speech_fname);
      // speech file for english
      if (!LbFileExists(spc_fname))
        spc_fname = prepare_file_fmtpath(FGrp_LrgSound,"speech_%s.dat",get_language_lwrstr(1));
      // Initialize sample banks
      if (!init_sound_heap_two_banks(sound_heap_memory, sound_heap_size, snd_fname, spc_fname, 1622))
      {
        LbMemoryFree(sound_heap_memory);
        sound_heap_memory = NULL;
        SoundDisabled = true;
        ERRORLOG("Unable to initialize sound heap. Sound disabled.");
      }
    }
    return true;
}