Ejemplo n.º 1
0
Archivo: mapdraw2.c Proyecto: rj76/kq
/*! \brief Save the current map
 *
 * Another even more useful than the original function
 */
void do_save_map (const char *filename)
{
   int p, q;
   PACKFILE *pf;

   pf = pack_fopen (filename, F_WRITE_PACKED);
   save_s_map (&gmap, pf);

   for (q = 0; q < 50; ++q) {
      save_s_entity (&gent[q], pf);
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (map[q * gmap.xsize + p], pf);
      }
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (b_map[q * gmap.xsize + p], pf);
      }
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (f_map[q * gmap.xsize + p], pf);
      }
   }

   pack_fwrite (z_map, (gmap.xsize * gmap.ysize), pf);
   pack_fwrite (sh_map, (gmap.xsize * gmap.ysize), pf);
   pack_fwrite (o_map, (gmap.xsize * gmap.ysize), pf);
   pack_fclose (pf);
}                               /* save_map () */
Ejemplo n.º 2
0
int save_scenario(int kind) {
	int i;

	for (i=0; save_dialog[i].proc; i++) {
      save_dialog[i].fg = colors[black];
      save_dialog[i].bg = colors[gray];
   }
	save_dialog[SAVE_LISTBOX].bg = colors[white];
	save_dialog[SAVE_EDIT].bg = colors[white];
	
	if (kind) strcpy(ext, "*.sce"); else strcpy(ext, "*.sav");

	file_index = for_each_file(ext, FA_ARCH, foo, 0);
	files = (files_t *)malloc(sizeof(files_t)*file_index);
	file_index=0;
	for_each_file(ext, FA_ARCH, add_file, 0);
	
	filename[0]='\0';
	
	if (kind==SL_SCENARIO) {
		save_dialog[SAVE_FRAME].dp = "Save Scenario";
		strcpy(ext, ".sce");
	} else {
		save_dialog[SAVE_FRAME].dp = "Save Game";
		strcpy(ext, ".sav");
	}
	
	i=1;
	if (do_dialog(save_dialog, -1)==SAVE_OKAY) {
		PACKFILE *file;
		unsigned short magic = MAGIC;
		
		if (filename[0]=='\0') {
			file = pack_fopen(files[save_dialog[SAVE_LISTBOX].d1].name, "wb");
		} else {
			char fn[16];
			sprintf(fn, "%s%s", filename, ext);
			file = pack_fopen(fn, "wb");
		}	
		
		if (file) {
			pack_fwrite(&game, sizeof(game_t), file);
			pack_fwrite(matrix, sizeof(tile_t)*game.tiles, file);
			pack_fwrite(players, sizeof(players_t)*8, file);
			pack_fwrite(&magic, sizeof(unsigned short), file);
			pack_fclose(file);

			printf("Game saved.\n");
			i=0;
		}
		if (i==1) alert("!ERROR", "Could not save the scenario", NULL, "OK", NULL, 'o', 0);
	}

	free(files);
	return i;
}
Ejemplo n.º 3
0
int save_midi(char *filename, MIDI *midi)
{
    int c;
    long len;
    PACKFILE *fp;
    int num_tracks = 0;
    
    if(!midi)
        return 1;
        
    fp = pack_fopen_password(filename, F_WRITE,"");                       /* open the file */
    
    if(!fp)
        return 2;
        
    for(c=0; c<MIDI_TRACKS; c++)
        if(midi->track[c].len > 0)
            num_tracks++;
            
    pack_fwrite((void *) "MThd", 4, fp);                      /* write midi header */
    
    pack_mputl(6, fp);                                        /* header chunk length = 6 */
    
    pack_mputw((num_tracks==1) ? 0 : 1, fp);                  /* MIDI file type */
    
    pack_mputw(num_tracks, fp);                               /* number of tracks */
    
    pack_mputw(midi->divisions, fp);                          /* beat divisions (negatives?) */
    
    for(c=0; c<num_tracks; c++)                               /* write each track */
    {
        pack_fwrite((void *) "MTrk", 4, fp);                    /* write track header */
        
        len = midi->track[c].len;
        pack_mputl(len, fp);                                    /* length of track chunk */
        
        if(pack_fwrite(midi->track[c].data, len, fp) != len)
            goto err;
    }
    
    pack_fclose(fp);
    return 0;
    
    /* oh dear... */
err:
    pack_fclose(fp);
    delete_file(filename);
    return 3;
}
Ejemplo n.º 4
0
static int copy_file(AL_CONST char *filename, AL_CONST char *dest_path)
{
   char *buffer = NULL;
   char dest_file[1024];
   PACKFILE *f;
   size_t size;
   
   if (!exists(filename))
      return -1;
   buffer = malloc(size = file_size_ex(filename));
   if (!buffer)
      return -1;
   append_filename(dest_file, dest_path, get_filename(filename), 1024);
   f = pack_fopen(filename, F_READ);
   if (!f) {
      free(buffer);
      return -1;
   }
   pack_fread(buffer, size, f);
   pack_fclose(f);
   f = pack_fopen(dest_file, F_WRITE);
   if (!f) {
      free(buffer);
      return -1;
   }
   pack_fwrite(buffer, size, f);
   pack_fclose(f);
   free(buffer);
   
   return 0;
}
Ejemplo n.º 5
0
/* saves a sample into the datafile format */
static int save_sample_in_datafile(DATAFILE *dat, AL_CONST int *fixed_prop, int pack, int pack_kids, int strip, int sort, int verbose, int extra, PACKFILE *f)
{
   SAMPLE *spl = (SAMPLE *)dat->dat;

   *allegro_errno = 0;

   pack_mputw((spl->stereo) ? -spl->bits : spl->bits, f);
   pack_mputw(spl->freq, f);
   pack_mputl(spl->len, f);
   if (spl->bits == 8) {
      pack_fwrite(spl->data, spl->len * ((spl->stereo) ? 2 : 1), f);
   }
   else {
      int i;

      for (i=0; i < (int)spl->len * ((spl->stereo) ? 2 : 1); i++) {
	 pack_iputw(((int16_t *)spl->data)[i], f);
      }
   }

   if (*allegro_errno)
      return FALSE;
   else
      return TRUE;
}
Ejemplo n.º 6
0
int save_s_entity(s_entity *s, PACKFILE *f)
{
    pack_putc(s->chrx, f);
    pack_putc(0, f);             /* alignment */
    pack_iputw(s->x, f);
    pack_iputw(s->y, f);
    pack_iputw(s->tilex, f);
    pack_iputw(s->tiley, f);
    pack_putc(s->eid, f);
    pack_putc(s->active, f);
    pack_putc(s->facing, f);
    pack_putc(s->moving, f);
    pack_putc(s->movcnt, f);
    pack_putc(s->framectr, f);
    pack_putc(s->movemode, f);
    pack_putc(s->obsmode, f);
    pack_putc(s->delay, f);
    pack_putc(s->delayctr, f);
    pack_putc(s->speed, f);
    pack_putc(s->scount, f);
    pack_putc(s->cmd, f);
    pack_putc(s->sidx, f);
    pack_putc(s->extra, f);
    pack_putc(s->chasing, f);
    pack_iputw(0, f);            /* alignment */
    pack_iputl(s->cmdnum, f);
    pack_putc(s->atype, f);
    pack_putc(s->snapback, f);
    pack_putc(s->facehero, f);
    pack_putc(s->transl, f);
    pack_fwrite(s->script, sizeof(s->script), f);
    return 0;
}
Ejemplo n.º 7
0
Archivo: disk.c Proyecto: rj76/kq
int save_s_player (s_player * s, PACKFILE * f)
{
   int i;
   pack_fwrite (s->name, sizeof (s->name), f);
   pack_putc (0, f);            /* alignment */
   pack_putc (0, f);            /* alignment */
   pack_putc (0, f);            /* alignment */
   pack_iputl (s->xp, f);
   pack_iputl (s->next, f);
   pack_iputl (s->lvl, f);
   pack_iputl (s->mrp, f);
   pack_iputl (s->hp, f);
   pack_iputl (s->mhp, f);
   pack_iputl (s->mp, f);
   pack_iputl (s->mmp, f);
   for (i = 0; i < NUM_STATS; ++i) {
      pack_iputl (s->stats[i], f);
   }
   for (i = 0; i < 16; ++i) {
      pack_putc (s->res[i], f);
   }
   for (i = 0; i < 24; ++i) {
      pack_putc (s->sts[i], f);
   }
   for (i = 0; i < 6; ++i) {
      pack_putc (s->eqp[i], f);
   }
   for (i = 0; i < 60; ++i) {
      pack_putc (s->spells[i], f);
   }
   pack_putc (0, f);            /* alignment */
   pack_putc (0, f);            /* alignment */
   return 0;
}
Ejemplo n.º 8
0
Archivo: disk.c Proyecto: rj76/kq
int save_s_marker (const s_marker * m, PACKFILE * f)
{
   pack_fwrite (m->name, sizeof (m->name), f);
   pack_iputw (m->x, f);
   pack_iputw (m->y, f);
   return 0;
}
Ejemplo n.º 9
0
/*! \brief Save all markers out to packfile
 *
 * Saves individual \sa s_marker objects to the specified PACKFILE.
 *
 * \param[out] marray - Current array of markers from whence data are pulled
 * \param[out] pf - PACKFILE to where data is written
 * \return     Non-0 on error, 0 on success
 */
size_t save_markers (s_marker_array *marray, PACKFILE *pf)
{
   size_t i;

   assert (marray && "marray == NULL");
   assert (pf && "pf == NULL");

   if (!marray || !pf) {
      printf ("NULL passed into save_markers()\n");
      return 1;
   }

   pack_iputw (marray->size, pf);
   if (pack_feof (pf)) {
      assert (0 && "pack_iputw() for marray->size received EOF signal.");
      printf ("Encountered EOF when writing marker array size.\n");
      return 2;
   }

   for (i = 0; i < marray->size; ++i) {
      pack_fwrite (marray->array[i].name, sizeof (marray->array[i].name), pf);
      pack_iputw (marray->array[i].x, pf);
      pack_iputw (marray->array[i].y, pf);

      if (pack_feof (pf)) {
         assert (0 && "pack_iputw() for marker->[xy] received EOF signal.");
         printf ("Encountered EOF when writing marker %dsize.\n", i);
         return 3;
      }
   }

   return 0;
}
Ejemplo n.º 10
0
/* save raw binary data */
static int save_binary(DATAFILE *dat, AL_CONST int *fixed_prop, int pack, int pack_kids, int strip, int sort, int verbose, int extra, PACKFILE *f)
{
   if (pack_fwrite(dat->dat, dat->size, f) < dat->size)
      return FALSE;

   return TRUE;
}
Ejemplo n.º 11
0
Archivo: disk.c Proyecto: rj76/kq
int save_s_map (s_map * sm, PACKFILE * f)
{
   int i;

   /* pack_putc (sm->map_no, f); */
   pack_putc (0, f); /* To maintain compatibility. */

   pack_putc (sm->zero_zone, f);
   pack_putc (sm->map_mode, f);
   pack_putc (sm->can_save, f);
   pack_putc (sm->tileset, f);
   pack_putc (sm->use_sstone, f);
   pack_putc (sm->can_warp, f);
   pack_putc (sm->extra_byte, f);
   pack_iputl (sm->xsize, f);
   pack_iputl (sm->ysize, f);
   pack_iputl (sm->pmult, f);
   pack_iputl (sm->pdiv, f);
   pack_iputl (sm->stx, f);
   pack_iputl (sm->sty, f);
   pack_iputl (sm->warpx, f);
   pack_iputl (sm->warpy, f);
   //pack_iputl (1, f);           /* Revision 1 */
   sm->revision = 2; // Force new revision: 2

   pack_iputl (sm->revision, f);           /* Revision 2 */
   pack_iputl (sm->extra_sdword2, f);
   pack_fwrite (sm->song_file, sizeof (sm->song_file), f);
   pack_fwrite (sm->map_desc, sizeof (sm->map_desc), f);

   /* Markers */
   pack_iputw (sm->num_markers, f);

   for (i = 0; i < sm->num_markers; ++i) {
      save_s_marker (&sm->markers[i], f);
   }

   /* Bounding boxes */
   pack_iputw (sm->num_bound_boxes, f);

   for (i = 0; i < sm->num_bound_boxes; ++i) {
      save_s_bound (&sm->bound_box[i], f);
   }

   return 0;
}
/* exports a bitmap into an external file */
static int export_jpeg(AL_CONST DATAFILE *dat, AL_CONST char *filename)
{
	PACKFILE *f = pack_fopen(filename, F_WRITE);

	if (f) {
		pack_fwrite(dat->dat, dat->size, f);
		pack_fclose(f);
	}

	return (errno == 0);
}
Ejemplo n.º 13
0
Archivo: disk.c Proyecto: rj76/kq
int save_s_tileset (s_tileset * s, PACKFILE * f)
{
   int i;
   pack_fwrite (s->icon_set, sizeof (s->icon_set), f);
   for (i = 0; i < MAX_ANIM; ++i) {
      pack_iputw (s->tanim[i].start, f);
      pack_iputw (s->tanim[i].end, f);
      pack_iputw (s->tanim[i].delay, f);
   }
   return 0;
}
Ejemplo n.º 14
0
int save_s_map(s_map *sm, PACKFILE *f)
{
    size_t i;

    assert(sm && "sm == NULL");
    assert(f && "f == NULL");

    /* pack_putc (sm->map_no, f); */
    pack_putc(0, f);             /* To maintain compatibility. */

    pack_putc(sm->zero_zone, f);
    pack_putc(sm->map_mode, f);
    pack_putc(sm->can_save, f);
    pack_putc(sm->tileset, f);
    pack_putc(sm->use_sstone, f);
    pack_putc(sm->can_warp, f);
    pack_putc(sm->extra_byte, f);
    pack_iputl(sm->xsize, f);
    pack_iputl(sm->ysize, f);
    pack_iputl(sm->pmult, f);
    pack_iputl(sm->pdiv, f);
    pack_iputl(sm->stx, f);
    pack_iputl(sm->sty, f);
    pack_iputl(sm->warpx, f);
    pack_iputl(sm->warpy, f);
    //pack_iputl (1, f);           /* Revision 1 */
    sm->revision = 2;            // Force new revision: 2

    pack_iputl(sm->revision, f);         /* Revision 2 */
    pack_iputl(sm->extra_sdword2, f);
    pack_fwrite(sm->song_file, sizeof(sm->song_file), f);
    pack_fwrite(sm->map_desc, sizeof(sm->map_desc), f);

    /* Markers */
    save_markers(&sm->markers, f);

    /* Bounding boxes */
    save_bounds(&sm->bounds, f);

    return 0;
}
Ejemplo n.º 15
0
void save_level(PACKFILE *file,LEVEL *data) {
     int i;
     pack_iputw(data->sizey,file);
     pack_iputw(data->sizex,file);
     pack_putc(data->bgtype,file);
     if (data->bgtype == 1) for (i=0;i<600;i++) {pack_putc(getr24(data->lines[i]),file); pack_putc(getg24(data->lines[i]),file); pack_putc(getb24(data->lines[i]),file);}
     pack_iputw(data->entitycnt,file);
     pack_fwrite(data->map,data->length,file);
     for(i=0;i<data->entitycnt;i++) {
         save_entity(file,&data->entities[i]);
     }
}
Ejemplo n.º 16
0
void dump_buffer(BUFFER *b, PACKFILE *f)
{
    int size;

    size = b->pos;

    if(b->bit_pos != 0)
        size ++;

    pack_putc(size, f);
    pack_fwrite(b->data, size, f);
}
Ejemplo n.º 17
0
int eof_copy_file(const char * src, const char * dest)
{
	PACKFILE * src_fp = NULL;
	PACKFILE * dest_fp = NULL;
	void *ptr = NULL;	//Used to buffer memory
	unsigned long src_size = 0;
	unsigned long i;

 	eof_log("eof_copy_file() entered", 1);

	if((src == NULL) || (dest == NULL))
		return 0;
	if(!ustricmp(src,dest))		//Special case:  The input and output file are the same
		return 0;				//Return success without copying any files

	src_size = (unsigned long)file_size_ex(src);
	if(src_size > LONG_MAX)
		return 0;	//Unable to validate I/O due to Allegro's usage of signed values
	src_fp = pack_fopen(src, "r");
	if(!src_fp)
	{
		return 0;
	}
	dest_fp = pack_fopen(dest, "w");
	if(!dest_fp)
	{
		(void) pack_fclose(src_fp);
		return 0;
	}
//Attempt to buffer the input file into memory for faster read and write
	ptr = malloc((size_t)src_size);
	if(ptr != NULL)
	{	//If a buffer large enough to store the input file was created
		long long_src_size = src_size;
		if((pack_fread(ptr, long_src_size, src_fp) != long_src_size) || (pack_fwrite(ptr, long_src_size, dest_fp) != long_src_size))
		{	//If there was an error reading from file or writing from memory
			free(ptr);	//Release buffer
			return 0;	//Return error
		}
		free(ptr);	//Release buffer
	}
	else
	{	//Otherwise copy the slow way (one byte at a time)
		for(i = 0; i < src_size; i++)
		{
			(void) pack_putc(pack_getc(src_fp), dest_fp);
		}
	}
	(void) pack_fclose(src_fp);
	(void) pack_fclose(dest_fp);
	return 1;
}
Ejemplo n.º 18
0
/* export raw binary data */
static int export_binary(AL_CONST DATAFILE *dat, AL_CONST char *filename)
{
   PACKFILE *f = pack_fopen(filename, F_WRITE);
   int ret = TRUE;

   if (f) {
      if (pack_fwrite(dat->dat, dat->size, f) < dat->size)
	 ret = FALSE;

      pack_fclose(f);
   }
   else
      ret = FALSE;

   return ret;
}
Ejemplo n.º 19
0
/* exports a sample into an external file */
static int export_sample(AL_CONST DATAFILE *dat, AL_CONST char *filename)
{
   SAMPLE *spl = (SAMPLE *)dat->dat;
   int bps = spl->bits/8 * ((spl->stereo) ? 2 : 1);
   int len = spl->len * bps;
   int i;
   int16_t s;
   PACKFILE *f;

   errno = 0;
   
   f = pack_fopen(filename, F_WRITE);

   if (f) {
      pack_fputs("RIFF", f);                 /* RIFF header */
      pack_iputl(36+len, f);                 /* size of RIFF chunk */
      pack_fputs("WAVE", f);                 /* WAV definition */
      pack_fputs("fmt ", f);                 /* format chunk */
      pack_iputl(16, f);                     /* size of format chunk */
      pack_iputw(1, f);                      /* PCM data */
      pack_iputw((spl->stereo) ? 2 : 1, f);  /* mono/stereo data */
      pack_iputl(spl->freq, f);              /* sample frequency */
      pack_iputl(spl->freq*bps, f);          /* avg. bytes per sec */
      pack_iputw(bps, f);                    /* block alignment */
      pack_iputw(spl->bits, f);              /* bits per sample */
      pack_fputs("data", f);                 /* data chunk */
      pack_iputl(len, f);                    /* actual data length */

      if (spl->bits == 8) {
	 pack_fwrite(spl->data, len, f);     /* write the data */
      }
      else {
	 for (i=0; i < (int)spl->len * ((spl->stereo) ? 2 : 1); i++) {
	    s = ((int16_t *)spl->data)[i];
	    pack_iputw(s^0x8000, f);
	 }
      }

      pack_fclose(f);
   }

   return (errno == 0);
}
Ejemplo n.º 20
0
int main(int argc, char *argv[])
{
    BITMAP *bmp;
    PACKFILE *f;

    if (argc != 3) {
        usage();
        return 1;
    }

    if (install_allegro(SYSTEM_NONE, &errno, atexit) != 0)
        return 1;
    set_color_conversion(COLORCONV_NONE);

    bmp = load_bitmap(argv[1], the_pal);
    if (!bmp) {
        printf("Error reading palette from '%s'\n", argv[1]);
        return 1;
    }

    destroy_bitmap(bmp);

    printf("Palette read from '%s'\n", argv[1]);
    printf("Creating RGB map\n");

    create_rgb_table(&the_map, the_pal, NULL);

    f = pack_fopen(argv[2], F_WRITE);
    if (!f) {
        printf("Error writing '%s'\n", argv[2]);
        return 1;
    }

    pack_fwrite(&the_map, sizeof(the_map), f);
    pack_fclose(f);

    printf("RGB mapping table written to '%s'\n", argv[2]);
    return 0;
}
Ejemplo n.º 21
0
/* saves a wave file to file pointer */
static int save_wav_fp(SAMPLE * sp, PACKFILE * fp)
{
	size_t channels, bits, freq;
	size_t data_size;
	size_t samples;
	size_t i, n;
	void * pval = NULL;
	unsigned short *data;

	eof_log("save_wav_fp() entered", 1);

	if(!sp || !fp)
	{
		return 0;
	}
	channels = sp->stereo ? (size_t)2 : (size_t)1;
	bits = (size_t)sp->bits;

	samples = (size_t)sp->len;
	data_size = samples * channels * (bits / 8);
	n = samples * channels;

	freq = (size_t)sp->freq;

	(void) pack_fputs("RIFF", fp);
	(void) pack_iputl(36 + (long)data_size, fp);
	(void) pack_fputs("WAVE", fp);

	(void) pack_fputs("fmt ", fp);
	(void) pack_iputl(16, fp);
	(void) pack_iputw(1, fp);
	(void) pack_iputw((int)channels, fp);
	(void) pack_iputl((long)freq, fp);
	(void) pack_iputl((long)(freq * channels * (bits / 8)), fp);	//ByteRate = SampleRate * NumChannels * BitsPerSample/8
	(void) pack_iputw((int)(channels * (bits / 8)), fp);
	(void) pack_iputw((int)bits, fp);

	(void) pack_fputs("data", fp);
	(void) pack_iputl((long)data_size, fp);

	if(bits == 8)
	{
		pval = sp->data;
		(void) pack_fwrite(pval, (long)(samples * channels), fp);
	}
	else if(bits == 16)
	{
		data = (unsigned short *)sp->data;
		for (i = 0; i < n; i++)
		{
			(void) pack_iputw((short)(data[i] - 0x8000), fp);
		}
	}
	else
	{
		(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "Unknown audio depth (%lu) when saving wav ALLEGRO_FILE.", (unsigned long) bits);
		eof_log(eof_log_string, 1);
		return 0;
	}

	return 1;
}
Ejemplo n.º 22
0
/* write_data:
 *  Custom write function to use Allegro packfile routines,
 *  rather than C streams.
 */
static void write_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
    PACKFILE *f = png_get_io_ptr(png_ptr);
    if ((png_uint_32)pack_fwrite(data, length, f) != length)
	png_error(png_ptr, "write error (loadpng calling pack_fwrite)");
}
Ejemplo n.º 23
0
// saves the data structure to disk
void save_options(Toptions *o, PACKFILE *fp) {
	pack_fwrite(o, sizeof(Toptions), fp);
}
Ejemplo n.º 24
0
/*
 * Compresses all the frames in the animation and writes to a gif file.
 * Nothing else like extensions or comments is written.
 *
 * Returns 0 on success.
 *
 * Note: All bitmaps must have a color depth of 8.
 */
int
algif_save_raw_animation (const char *filename, GIF_ANIMATION *gif)
{
    int frame;
    int i, j;
    PACKFILE *file;

    file = pack_fopen (filename, "w");
    if (!file)
        return -1;

    pack_fwrite ("GIF89a", 6, file);
    pack_iputw (gif->width, file);
    pack_iputw (gif->height, file);
    /* 7 global palette
     * 456 color richness
     * 3 sorted
     * 012 palette bits
     */
    for (i = 1, j = 0; i < gif->palette.colors_count; i *= 2, j++);
    pack_putc ((j ? 128 : 0) + 64 + 32 + 16 + (j ? j - 1 : 0), file);
    pack_putc (gif->background_index, file);
    pack_putc (0, file);        /* No aspect ratio. */

    if (j)
        write_palette (file, &gif->palette, j);

    if (gif->loop != -1)
    /* Loop count extension. */
    {
        pack_putc (0x21, file); /* Extension Introducer. */
        pack_putc (0xff, file); /* Application Extension. */
        pack_putc (11, file);    /* Size. */
        pack_fwrite ("NETSCAPE2.0", 11, file);
        pack_putc (3, file); /* Size. */
        pack_putc (1, file);
        pack_iputw (gif->loop, file);
        pack_putc (0, file);
    }

    for (frame = 0; frame < gif->frames_count; frame++)
    {
        int w = gif->frames[frame].bitmap_8_bit->w;
        int h = gif->frames[frame].bitmap_8_bit->h;

        pack_putc (0x21, file); /* Extension Introducer. */
        pack_putc (0xf9, file); /* Graphic Control Extension. */
        pack_putc (4, file);    /* Size. */
        /* Disposal method, and enable transparency. */
        i = gif->frames[frame].disposal_method << 2;
        if (gif->frames[frame].transparent_index != -1)
            i |= 1;
        pack_putc (i, file);
        pack_iputw (gif->frames[frame].duration, file); /* In 1/100th seconds. */
        if (gif->frames[frame].transparent_index != -1)
            pack_putc (gif->frames[frame].transparent_index, file);       /* Transparent color index. */
        else
             pack_putc (0, file);
        pack_putc (0x00, file); /* Terminator. */

        pack_putc (0x2c, file); /* Image Descriptor. */
        pack_iputw (gif->frames[frame].xoff, file);
        pack_iputw (gif->frames[frame].yoff, file);
        pack_iputw (w, file);
        pack_iputw (h, file);

         /* 7: local palette
         * 6: interlaced
         * 5: sorted
         * 012: palette bits
         */

        for (i = 1, j = 0; i < gif->frames[frame].palette.colors_count; i *= 2, j++);
        pack_putc ((j ? 128 : 0) + (j ? j - 1 : 0), file);

        if (j)
            write_palette (file, &gif->frames[frame].palette, j);

        LZW_encode (file, gif->frames[frame].bitmap_8_bit);

        pack_putc (0x00, file); /* Terminator. */
    }

    pack_putc (0x3b, file);     /* Trailer. */

    pack_fclose (file);
    return 0;
}
Ejemplo n.º 25
0
/*! \brief Save game
 *
 * You guessed it... save the game.
 *
 * \returns 0 if save failed, 1 if success
 */
static int save_game (void)
{
   PACKFILE *sdat;
   size_t a, b;

   return save_game_92 ();

   /* Rest of this function is no longer used */

   for (b = 0; b < PSIZE; b++) {
      sid[save_ptr][b] = 0;
      shp[save_ptr][b] = 0;
      smp[save_ptr][b] = 0;
      slv[save_ptr][b] = 0;
   }
   for (b = 0; b < numchrs; b++) {
      sid[save_ptr][b] = pidx[b];
      shp[save_ptr][b] = party[pidx[b]].hp * 100 / party[pidx[b]].mhp;
      if (party[pidx[b]].mmp > 0)
         smp[save_ptr][b] = party[pidx[b]].mp * 100 / party[pidx[b]].mmp;
      slv[save_ptr][b] = party[pidx[b]].lvl;
   }
   snc[save_ptr] = numchrs;
   sgp[save_ptr] = gp;
   smin[save_ptr] = kmin;
   shr[save_ptr] = khr;
   sprintf (strbuf, "sg%d.sav", save_ptr);
   sdat = pack_fopen (kqres (SAVE_DIR, strbuf), F_WRITE_PACKED);
   if (!sdat) {
      message (_("Could not save game data."), 255, 0, 0, 0);
      return 0;
   }
   pack_putc (kq_version, sdat);
   pack_iputl (numchrs, sdat);
   pack_iputl (gp, sdat);
   pack_iputl (shr[save_ptr], sdat);
   pack_iputl (smin[save_ptr], sdat);
   for (a = 0; a < PSIZE; a++) {
      pack_iputl (pidx[a], sdat);
   }
   for (a = 0; a < MAXCHRS; a++) {
      save_s_player (&party[a], sdat);
   }
   pack_fwrite (curmap, 16, sdat);
   for (a = 0; a < sizeof (progress); a++) {  /* sizeof(progress) is 1750 */
      pack_putc (progress[a], sdat);
   }
   for (a = 0; a < NUMSHOPS; a++) {           /* NUMSHOPS is 50 */
      pack_putc (shop_time[a], sdat);
   }
   for (a = 0; a < SIZE_SAVE_RESERVE1; a++) { /* SAVE_RESERVE_SIZE1 is 150 */
      pack_putc (0, sdat);
   }
   for (a = 0; a < sizeof (save_spells); a++) { /* sizeof(save_spells) is 50 */
      pack_putc (save_spells[a], sdat);
   }
   for (a = 0; a < sizeof (treasure); a++) {    /* sizeof(treasure) is 1000 */
      pack_putc (treasure[a], sdat);
   }
   for (a = 0; a < NUMSHOPS; a++) {
      for (b = 0; b < SHOPITEMS; b++) {
         pack_iputw (shops[a].items_current[b], sdat);
      }
   }
   for (a = 0; a < MAX_INV; a++) {
      pack_iputw (g_inv[a][0], sdat);
      pack_iputw (g_inv[a][1], sdat);
   }
   /* PH FIXME: do we _really_ want things like controls and screen */
   /* mode to be saved/loaded ? */
   /* WK: No. */
   pack_iputl (gsvol, sdat);
   pack_iputl (gmvol, sdat);
   pack_putc (windowed, sdat);
   pack_putc (stretch_view, sdat);
   pack_putc (wait_retrace, sdat);
   pack_iputl (kup, sdat);
   pack_iputl (kdown, sdat);
   pack_iputl (kleft, sdat);
   pack_iputl (kright, sdat);
   pack_iputl (kalt, sdat);
   pack_iputl (kctrl, sdat);
   pack_iputl (kenter, sdat);
   pack_iputl (kesc, sdat);
   pack_iputl (jbalt, sdat);
   pack_iputl (jbctrl, sdat);
   pack_iputl (jbenter, sdat);
   pack_iputl (jbesc, sdat);
   /* End worthless */
   pack_iputw (g_ent[0].tilex, sdat);
   pack_iputw (g_ent[0].tiley, sdat);
   pack_fclose (sdat);
   return 1;
}
Ejemplo n.º 26
0
/*! \brief Save game 92
 *
 * Save the game, using KQ Save Game Format 92 (Beta)
 * Author: Winter Knight
 *
 * \returns 0 if save failed, 1 if success
 */
static int save_game_92 (void)
{
   size_t a, b, c, d;
   PACKFILE *sdat;

   for (b = 0; b < PSIZE; b++) {
      sid[save_ptr][b] = 0;
      shp[save_ptr][b] = 0;
      smp[save_ptr][b] = 0;
      slv[save_ptr][b] = 0;
   }
   for (b = 0; b < numchrs; b++) {
      sid[save_ptr][b] = pidx[b];
      shp[save_ptr][b] = party[pidx[b]].hp * 100 / party[pidx[b]].mhp;
      if (party[pidx[b]].mmp > 0)
         smp[save_ptr][b] = party[pidx[b]].mp * 100 / party[pidx[b]].mmp;
      slv[save_ptr][b] = party[pidx[b]].lvl;
   }
   snc[save_ptr] = numchrs;
   sgp[save_ptr] = gp;
   smin[save_ptr] = kmin;
   shr[save_ptr] = khr;
   sprintf (strbuf, "sg%d.sav", save_ptr);
   sdat = pack_fopen (kqres (SAVE_DIR, strbuf), F_WRITE_PACKED);
   if (!sdat) {
      message (_("Could not save game data."), 255, 0, 0, 0);
      return 0;
   }


   pack_putc (kq_version, sdat);
   pack_iputl (gp, sdat);
   pack_iputw (shr[save_ptr], sdat);
   pack_iputw (smin[save_ptr], sdat);

   /* Save number of, and which characters are in the party */
   pack_iputw (numchrs, sdat);
   for (a = 0; a < numchrs; a++) {
      pack_iputw (pidx[a], sdat);
   }

   /* Save number of, and data on all characters in game */
   pack_iputw (MAXCHRS, sdat);
   for (a = 0; a < MAXCHRS; a++) {
      save_s_player (&party[a], sdat);
   }

   /* Save map name and location */
   pack_iputw (strlen (curmap), sdat);
   pack_fwrite (curmap, strlen (curmap), sdat);

   pack_iputw (g_ent[0].tilex, sdat);
   pack_iputw (g_ent[0].tiley, sdat);


   /* Save quest info */
   for (a = sizeof (progress); a > 0; a--) {
      if (progress[a - 1] > 0)
         break;
   }

   pack_iputw (a, sdat);
   for (b = 0; b < a; b++)
      pack_putc (progress[b], sdat);

   /* Save treasure info */
   for (a = sizeof (treasure); a > 0; a--) {
      if (treasure[a - 1] > 0)
         break;
   }

   pack_iputw (a, sdat);
   for (b = 0; b < a; b++)
      pack_putc (treasure[b], sdat);

   /* Save spell info (P_REPULSE is 48) */
   pack_iputw (sizeof (save_spells), sdat);
   for (a = 0; a < sizeof (save_spells); a++) { /* sizeof(save_spells) is 50 */
      pack_putc (save_spells[a], sdat);
   }

   /* Save player inventory */
   pack_iputw (MAX_INV, sdat);
   for (a = 0; a < MAX_INV; a++) {
      pack_iputw (g_inv[a][0], sdat);
      pack_iputw (g_inv[a][1], sdat);
   }

   /* Save special items */
   for (a = MAX_SPECIAL_ITEMS + 1; a > 0; a--) {
      if (player_special_items[a - 1])
         break;
   }

   pack_iputw (a, sdat);
   for (b = 0; b < a; b++) {
      pack_putc (player_special_items[b], sdat);
   }

   /* Save shop info (last visit time and number of items) */
   /* Find last index of shop that the player has visited. */
   for (a = num_shops; a > 0; a--) {
      if (shop_time[a - 1] > 0)
         break;
   }

   pack_iputw (a, sdat);
   for (b = 0; b < a; b++) {
      pack_iputw (shop_time[b], sdat);

      /* Find last valid (non-zero) shop item for this shop */
      for (c = SHOPITEMS; c > 0; c--)
         if (shops[b].items[c - 1] > 0)
            break;

      pack_iputw (c, sdat);
      for (d = 0; d < c; d++)
         pack_iputw (shops[b].items_current[d], sdat);
   }


   pack_fclose (sdat);
   return 1;
}