int load_s_player (s_player * s, PACKFILE * f) { int i; pack_fread (s->name, sizeof (s->name), f); pack_getc (f); /* alignment */ pack_getc (f); /* alignment */ pack_getc (f); /* alignment */ s->xp = pack_igetl (f); s->next = pack_igetl (f); s->lvl = pack_igetl (f); s->mrp = pack_igetl (f); s->hp = pack_igetl (f); s->mhp = pack_igetl (f); s->mp = pack_igetl (f); s->mmp = pack_igetl (f); for (i = 0; i < NUM_STATS; ++i) { s->stats[i] = pack_igetl (f); } for (i = 0; i < 16; ++i) { s->res[i] = pack_getc (f); } for (i = 0; i < 24; ++i) { s->sts[i] = pack_getc (f); } for (i = 0; i < 6; ++i) { s->eqp[i] = pack_getc (f); } for (i = 0; i < 60; ++i) { s->spells[i] = pack_getc (f); } pack_getc (f); /* alignment */ pack_getc (f); /* alignment */ return 0; }
int load_s_map (s_map * sm, PACKFILE * f) { int i; sm->map_no = pack_getc (f); sm->zero_zone = pack_getc (f); sm->map_mode = pack_getc (f); sm->can_save = pack_getc (f); sm->tileset = pack_getc (f); sm->use_sstone = pack_getc (f); sm->can_warp = pack_getc (f); sm->extra_byte = pack_getc (f); sm->xsize = pack_igetl (f); sm->ysize = pack_igetl (f); sm->pmult = pack_igetl (f); sm->pdiv = pack_igetl (f); sm->stx = pack_igetl (f); sm->sty = pack_igetl (f); sm->warpx = pack_igetl (f); sm->warpy = pack_igetl (f); sm->revision = pack_igetl (f); sm->extra_sdword2 = pack_igetl (f); pack_fread (sm->song_file, sizeof (sm->song_file), f); pack_fread (sm->map_desc, sizeof (sm->map_desc), f); if (sm->revision >= 1) { /* Markers stuff */ sm->num_markers = pack_igetw (f); sm->markers = (s_marker *) realloc (sm->markers, sm->num_markers * sizeof (s_marker)); for (i = 0; i < sm->num_markers; ++i) { load_s_marker (&sm->markers[i], f); } if (sm->revision >= 2) { /* Bounding boxes stuff */ sm->num_bound_boxes = pack_igetw (f); sm->bound_box = (s_bound *) realloc (sm->bound_box, sm->num_bound_boxes * sizeof (s_bound)); for (i = 0; i < sm->num_bound_boxes; ++i) { load_s_bound (&sm->bound_box[i], f); } } else { sm->num_bound_boxes = 0; } } else { sm->num_markers = 0; sm->num_bound_boxes = 0; } return 0; }
void load_entity(PACKFILE *file,ENTITY *data) { data->x = pack_igetl(file); data->y = pack_igetl(file); data->speed = pack_igetl(file); data->type = pack_getc(file); data->data1 = pack_igetw(file); data->data2 = pack_igetw(file); data->data3 = pack_igetw(file); data->data4 = pack_igetw(file); data->health = pack_igetw(file); data->maxcooldown = pack_igetl(file); data->cooldown = data->maxcooldown; }
int load_s_entity(s_entity *s, PACKFILE *f) { s->chrx = pack_getc(f); pack_getc(f); /* alignment */ s->x = pack_igetw(f); s->y = pack_igetw(f); s->tilex = pack_igetw(f); s->tiley = pack_igetw(f); s->eid = pack_getc(f); s->active = pack_getc(f); s->facing = pack_getc(f); s->moving = pack_getc(f); s->movcnt = pack_getc(f); s->framectr = pack_getc(f); s->movemode = pack_getc(f); s->obsmode = pack_getc(f); s->delay = pack_getc(f); s->delayctr = pack_getc(f); s->speed = pack_getc(f); s->scount = pack_getc(f); s->cmd = pack_getc(f); s->sidx = pack_getc(f); s->extra = pack_getc(f); s->chasing = pack_getc(f); pack_igetw(f); /* alignment */ s->cmdnum = pack_igetl(f); s->atype = pack_getc(f); s->snapback = pack_getc(f); s->facehero = pack_getc(f); s->transl = pack_getc(f); pack_fread(s->script, sizeof(s->script), f); return 0; }
int load_s_map(s_map *sm, PACKFILE *f) { sm->map_no = pack_getc(f); sm->zero_zone = pack_getc(f); sm->map_mode = pack_getc(f); sm->can_save = pack_getc(f); sm->tileset = pack_getc(f); sm->use_sstone = pack_getc(f); sm->can_warp = pack_getc(f); sm->extra_byte = pack_getc(f); sm->xsize = pack_igetl(f); sm->ysize = pack_igetl(f); sm->pmult = pack_igetl(f); sm->pdiv = pack_igetl(f); sm->stx = pack_igetl(f); sm->sty = pack_igetl(f); sm->warpx = pack_igetl(f); sm->warpy = pack_igetl(f); sm->revision = pack_igetl(f); sm->extra_sdword2 = pack_igetl(f); pack_fread(sm->song_file, sizeof(sm->song_file), f); pack_fread(sm->map_desc, sizeof(sm->map_desc), f); if (sm->revision >= 1) { /* Markers stuff */ load_markers(&sm->markers, f); if (sm->revision >= 2) { /* Bounding boxes stuff */ load_bounds(&sm->bounds, f); } else { sm->bounds.size = 0; } } else { sm->markers.size = 0; sm->bounds.size = 0; } return 0; }
/* loads a MSK file (Animator and Animator Pro format) */ Mask *load_msk_file(const char *filename) { #if (MAKE_VERSION(4, 2, 1) >= MAKE_VERSION(ALLEGRO_VERSION, \ ALLEGRO_SUB_VERSION, \ ALLEGRO_WIP_VERSION)) int orig_size = file_size(filename); #else int orig_size = file_size_ex(filename); #endif int i, c, u, v, byte, magic, size; Mask *mask = NULL; PACKFILE *f; f = pack_fopen(filename, F_READ); if (!f) return NULL; size = pack_igetl(f); magic = pack_igetw(f); /* Animator Pro MSK format */ if ((size == orig_size) && (magic == 0x9500)) { Image *image; int x, y; pack_fclose(f); /* just load an Animator Pro PIC file */ image = load_pic_file(filename, &x, &y, NULL); if ((!image) || (image->imgtype != IMAGE_BITMAP)) { if (image) image_free(image); } else { mask = mask_new(); mask->x = x; mask->y = y; mask->w = image->w; mask->h = image->h; mask->bitmap = image; } } /* Animator MSK format */ else if (orig_size == 8000) { mask = mask_new(); mask_replace(mask, 0, 0, 320, 200); u = v = 0; for (i=0; i<8000; i++) { byte = pack_getc (f); for (c=0; c<8; c++) { mask->bitmap->putpixel(u, v, byte & (1<<(7-c))); u++; if (u == 320) { u = 0; v++; } } } pack_fclose(f); } else { pack_fclose(f); } return mask; }
/*! \brief Load mini stats * * This loads the mini stats for each saved game. * These mini stats are just for displaying info about the save game on the * save/load game screen. */ void load_sgstats (void) { PACKFILE *ldat; int a, b, c; unsigned char vc; s_player tpm; for (a = 0; a < NUMSG; a++) { sprintf (strbuf, "sg%d.sav", a); ldat = pack_fopen (kqres (SAVE_DIR, strbuf), F_READ_PACKED); if (!ldat) { snc[a] = 0; sgp[a] = 0; shr[a] = 0; smin[a] = 0; for (b = 0; b < PSIZE; b++) { sid[a][b] = 0; shp[a][b] = 0; smp[a][b] = 0; } } else { vc = pack_getc (ldat); if (vc == 92) { sgp[a] = pack_igetl (ldat); shr[a] = pack_igetw (ldat); smin[a] = pack_igetw (ldat); snc[a] = pack_igetw (ldat); for (b = 0; b < snc[a]; b++) { sid[a][b] = pack_igetw (ldat); // sid[a][b] = 0; // Temp: Debugging / Testing } pack_igetw (ldat); // Number of characters in game. Assume MAXCHRS for (b = 0; b < MAXCHRS; b++) { load_s_player (&tpm, ldat); for (c = 0; c < snc[a]; c++) { if (b == sid[a][c]) { slv[a][c] = tpm.lvl; shp[a][c] = tpm.hp * 100 / tpm.mhp; if (tpm.mmp > 0) smp[a][c] = tpm.mp * 100 / tpm.mmp; else smp[a][c] = 0; } } } } else if (vc == 91) { snc[a] = pack_igetl (ldat); sgp[a] = pack_igetl (ldat); shr[a] = pack_igetl (ldat); smin[a] = pack_igetl (ldat); for (b = 0; b < PSIZE; b++) { sid[a][b] = pack_igetl (ldat); } for (b = 0; b < MAXCHRS; b++) { load_s_player (&tpm, ldat); for (c = 0; c < PSIZE; c++) { if (b == sid[a][c]) { slv[a][c] = tpm.lvl; shp[a][c] = tpm.hp * 100 / tpm.mhp; if (tpm.mmp > 0) smp[a][c] = tpm.mp * 100 / tpm.mmp; else smp[a][c] = 0; } } } } else snc[a] = -1; pack_fclose (ldat); } } }
/*! \brief Load game * * Loads game using KQ save game format 92 (Beta) * Author: Winter Knight * \returns 1 if load succeeded, 0 otherwise */ static int load_game_92 (PACKFILE *sdat) { size_t a, b, c, d; /* Already got kq_version */ gp = pack_igetl (sdat); khr = pack_igetw (sdat); kmin = pack_igetw (sdat); /* Load number of, and which characters in party */ numchrs = pack_igetw (sdat); if (numchrs > PSIZE) { message (_("Error. numchrs in saved game > PSIZE"), 255, 0, 0, 0); return 0; } for (a = 0; a < numchrs; a++) { pidx[a] = pack_igetw (sdat); g_ent[a].eid = pidx[a]; g_ent[a].active = 1; } /* Zero set empty party character(s), if any */ for (; a < PSIZE; a++) { pidx[a] = 0; g_ent[a].active = 0; } /* Load number of, and data on all characters in game */ pack_igetw (sdat); /* max number of characters is fixed in KQ */ for (a = 0; a < MAXCHRS; a++) { load_s_player (&party[a], sdat); } /* Load map name and location */ a = pack_igetw (sdat); if (a > sizeof (curmap)) { message (_("Error. number of chars in saved game > sizeof(curmap)"), 255, 0, 0, 0); return 0; } pack_fread (curmap, a, sdat); curmap[a] = 0; // pack_fread does not append a NULL to the end of a string. g_ent[0].tilex = pack_igetw (sdat); g_ent[0].tiley = pack_igetw (sdat); /* Load Quest Info */ b = pack_igetw (sdat); if (b > sizeof (progress)) { message (_("Error. number of progress indicators > sizeof(progress)"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) progress[a] = pack_getc (sdat); /* zero-set blank Quest Info */ for (; a < sizeof (progress); a++) progress[a] = 0; /* Load treasure info */ b = pack_igetw (sdat); if (b > sizeof (treasure)) { message (_("Error. number of treasure indicators > sizeof(treasure)"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) treasure[a] = pack_getc (sdat); /* zero-set blank treasure info */ for (; a < sizeof (treasure); a++) treasure[a] = 0; /* Load spell info */ b = pack_igetw (sdat); if (b > sizeof (save_spells)) { message (_("Error. number of non-combat spell indicators > sizeof(save_spells)"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) save_spells[a] = pack_getc (sdat); /* zero-set empty spell slots */ for (; a < sizeof (save_spells); a++) save_spells[a] = 0; /* Load player inventory */ b = pack_igetw (sdat); if (b > MAX_INV) { message (_("Error. number of inventory items > MAX_INV"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) { g_inv[a][0] = pack_igetw (sdat); g_inv[a][1] = pack_igetw (sdat); } /* zero-set empty inventory slots */ for (; a < MAX_INV; a++) { g_inv[a][0] = 0; g_inv[a][1] = 0; } /* Load special items info */ b = pack_igetw (sdat); if (b > MAX_SPECIAL_ITEMS) { message (_("Error. number of special items > MAX_SPECIAL_ITEMS"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) player_special_items[a] = pack_getc (sdat); /* index */ /* zero-set empty special item slots */ for (; a < MAX_SPECIAL_ITEMS; a++) player_special_items[a] = 0; /* Load shop info (last visit time and number of items) */ b = pack_igetw (sdat); if (b > NUMSHOPS) { message (_("Error. number of shops saved > NUMSHOPS"), 255, 0, 0, 0); return 0; } /* b = number of shop * a = current shop index * c = number of items in current shop * d = current item index */ for (a = 0; a < b; a++) { shop_time[a] = pack_igetw (sdat); c = pack_igetw (sdat); for (d = 0; d < c; d++) shops[a].items_current[d] = pack_igetw (sdat); for (; d < SHOPITEMS; d++) shops[a].items_current[d] = shops[a].items_max[d]; } /* Replenish all shops that were not saved (haven't been visited yet) */ for (a = b; a < NUMSHOPS; a++) { for (d = 0; d < SHOPITEMS; d++) shops[a].items_current[d] = shops[a].items_max[d]; } return 1; }
int load_game_91 (PACKFILE *sdat) { unsigned int a, b; numchrs = pack_igetl (sdat); gp = pack_igetl (sdat); khr = pack_igetl (sdat); kmin = pack_igetl (sdat); for (a = 0; a < PSIZE; a++) { pidx[a] = pack_igetl (sdat); g_ent[a].active = 0; if (a < numchrs) { g_ent[a].eid = pidx[a]; g_ent[a].active = 1; } } for (a = 0; a < MAXCHRS; a++) { load_s_player (&party[a], sdat); } pack_fread (curmap, 16, sdat); for (a = 0; a < SIZE_PROGRESS; a++) { /* 1750 */ progress[a] = pack_getc (sdat); } for (a = 0; a < NUMSHOPS; a++) { /* 50 */ shop_time[a] = pack_getc (sdat); } for (a = 0; a < SIZE_SAVE_RESERVE1; a++) { /* 150 */ pack_getc (sdat); } for (a = 0; a < SIZE_SAVE_SPELL; a++) { /* 50 */ save_spells[a] = pack_getc (sdat); } for (a = 0; a < sizeof (treasure); a++) { treasure[a] = pack_getc (sdat); } for (a = 0; a < NUMSHOPS; a++) { for (b = 0; b < SHOPITEMS; b++) { shops[a].items_current[b] = pack_igetw (sdat); } } for (a = 0; a < MAX_INV; a++) { g_inv[a][0] = pack_igetw (sdat); g_inv[a][1] = pack_igetw (sdat); } /* Bunch of 0s for alignment */ pack_igetl (sdat); pack_igetl (sdat); pack_getc (sdat); pack_getc (sdat); pack_getc (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); /* End worthless */ g_ent[0].tilex = pack_igetw (sdat); g_ent[0].tiley = pack_igetw (sdat); /* Fill special_items array with info from saved game */ #define P_UCOIN 36 #define P_CANCELROD 37 #define P_GOBLINITEM 17 #define P_UNDEADJEWEL 35 #define P_WSTONES 24 #define P_BSTONES 25 #define P_EMBERSKEY 46 #define P_BRONZEKEY 70 #define P_DENORIAN 55 #define P_OPALHELMET 43 #define P_OPALSHIELD 50 #define P_IRONKEY 66 #define P_OPALBAND 69 #define P_OPALARMOUR 90 #define P_CAVEKEY 71 #define P_TALK_TSORIN 108 #define P_TALKOLDMAN 110 #define SI_UCOIN 0 #define SI_CANCELROD 1 #define SI_JADEPENDANT 2 #define SI_UNDEADJEWEL 3 #define SI_WHITESTONE 4 #define SI_BLACKSTONE 5 #define SI_EMBERSKEY 6 #define SI_BRONZEKEY 7 #define SI_DENORIANSTATUE 8 #define SI_OPALHELMET 9 #define SI_OPALSHIELD 10 #define SI_IRONKEY 11 #define SI_OPALBAND 12 #define SI_OPALARMOUR 13 #define SI_CAVEKEY 14 #define SI_NOTE_TSORIN 15 #define SI_NOTE_DERIG 16 #define SI_RUSTYKEY 17 if (progress[P_UCOIN] == 2) player_special_items[SI_UCOIN] = 1; if (progress[P_CANCELROD] == 1) player_special_items[SI_CANCELROD] = 1; if (progress[P_GOBLINITEM] == 1) player_special_items[SI_JADEPENDANT] = 1; if (progress[P_UNDEADJEWEL] == 1) player_special_items[SI_UNDEADJEWEL] = 1; if (progress[P_WSTONES] > 0) player_special_items[SI_WHITESTONE] = progress[P_WSTONES]; if (progress[P_BSTONES] > 0) player_special_items[SI_BLACKSTONE] = progress[P_BSTONES]; if (progress[P_EMBERSKEY] == 2) player_special_items[SI_EMBERSKEY] = 1; if (progress[P_BRONZEKEY] == 1) player_special_items[SI_BRONZEKEY] = 1; if (progress[P_DENORIAN] == 3 || progress[P_DENORIAN] == 4) player_special_items[SI_DENORIANSTATUE] = 1; if (progress[P_OPALHELMET] == 1) player_special_items[SI_OPALHELMET] = 1; if (progress[P_OPALSHIELD] == 1) player_special_items[SI_OPALSHIELD] = 1; if (progress[P_OPALBAND] == 1) player_special_items[SI_OPALBAND] = 1; if (progress[P_OPALARMOUR] == 1) player_special_items[SI_OPALARMOUR] = 1; if (progress[P_CAVEKEY] == 1) player_special_items[SI_CAVEKEY] = 1; if (progress[P_IRONKEY] == 1) player_special_items[SI_IRONKEY] = 1; if (progress[P_TALK_TSORIN] == 1) player_special_items[SI_NOTE_TSORIN] = 1; if (progress[P_TALK_TSORIN] == 2) player_special_items[SI_NOTE_DERIG] = 1; if (progress[P_TALKOLDMAN] > 2) player_special_items[SI_RUSTYKEY] = 1; #if 0 a = 0; if (progress[P_UCOIN] == 2) { strcpy (special_items[a].name, _("Unadium coin")); strcpy (special_items[a].description, _("Use to reach ruins")); special_items[a].quantity = 1; special_items[a].icon = 50; a++; } if (progress[P_CANCELROD] == 1) { strcpy (special_items[a].name, _("Cancellation Rod")); strcpy (special_items[a].description, _("Nullify magic")); special_items[a].quantity = 1; special_items[a].icon = 51; a++; } if (progress[P_GOBLINITEM] == 1) { strcpy (special_items[a].name, _("Jade Pendant")); strcpy (special_items[a].description, _("Magical goblin gem")); special_items[a].quantity = 1; special_items[a].icon = 52; a++; } if (progress[P_UNDEADJEWEL] == 1) { strcpy (special_items[a].name, _("Goblin Jewel")); strcpy (special_items[a].description, _("Precious artifact")); special_items[a].quantity = 1; special_items[a].icon = 53; a++; } if (progress[P_WSTONES] > 0) { strcpy (special_items[a].name, _("White Stone")); strcpy (special_items[a].description, _("Smooth white rock")); special_items[a].quantity = progress[P_WSTONES]; special_items[a].icon = 54; a++; } if (progress[P_BSTONES] > 0) { strcpy (special_items[a].name, _("Black Stone")); strcpy (special_items[a].description, _("Smooth black rock")); special_items[a].quantity = progress[P_BSTONES]; special_items[a].icon = 55; a++; } if (progress[P_EMBERSKEY] == 2) { strcpy (special_items[a].name, _("Ember's Key")); strcpy (special_items[a].description, _("Unlock stuff")); special_items[a].quantity = 1; special_items[a].icon = 56; a++; } if (progress[P_BRONZEKEY] == 1) { strcpy (special_items[a].name, _("Bronze Key")); strcpy (special_items[a].description, _("Unlock stuff")); special_items[a].quantity = 1; special_items[a].icon = 57; a++; } if (progress[P_DENORIAN] == 3 || progress[P_DENORIAN] == 4) { strcpy (special_items[a].name, _("Denorian Statue")); strcpy (special_items[a].description, _("Broken in half")); special_items[a].quantity = 1; special_items[a].icon = 58; a++; } if (progress[P_OPALHELMET] == 1) { strcpy (special_items[a].name, _("Opal Helmet")); strcpy (special_items[a].description, _("Piece of opal set")); special_items[a].quantity = 1; special_items[a].icon = 59; a++; } if (progress[P_OPALSHIELD] == 1) { strcpy (special_items[a].name, _("Opal Shield")); strcpy (special_items[a].description, _("Piece of opal set")); special_items[a].quantity = 1; special_items[a].icon = 60; a++; } if (progress[P_IRONKEY] == 1) { strcpy (special_items[a].name, _("Iron Key")); strcpy (special_items[a].description, _("Unlock stuff")); special_items[a].quantity = 1; special_items[a].icon = 61; a++; } if (progress[P_OPALBAND] == 1) { strcpy (special_items[a].name, _("Opal Band")); strcpy (special_items[a].description, _("Piece of opal set")); special_items[a].quantity = 1; special_items[a].icon = 62; a++; } if (progress[P_OPALARMOUR] == 1) { strcpy (special_items[a].name, _("Opal Armour")); strcpy (special_items[a].description, _("Piece of opal set")); special_items[a].quantity = 1; special_items[a].icon = 14; a++; } if (progress[P_CAVEKEY] == 1) { strcpy (special_items[a].name, _("Cave Key")); strcpy (special_items[a].description, _("Unlock stuff")); special_items[a].quantity = 1; special_items[a].icon = 63; a++; } if (progress[P_TALK_TSORIN] == 1) { strcpy (special_items[a].name, _("Tsorin's Note")); strcpy (special_items[a].description, _("Sealed envelope")); special_items[a].quantity = 1; special_items[a].icon = 18; a++; } if (progress[P_TALK_TSORIN] == 2) { strcpy (special_items[a].name, _("Derig's Note")); strcpy (special_items[a].description, _("Encrypted message")); special_items[a].quantity = 1; special_items[a].icon = 18; a++; } if (progress[P_TALKOLDMAN] > 2) { strcpy (special_items[a].name, _("Rusty Key")); strcpy (special_items[a].description, _("Unlock grotto ruins")); special_items[a].quantity = 1; special_items[a].icon = 64; a++; } #endif #undef P_UCOIN #undef P_CANCELROD #undef P_GOBLINITEM #undef P_UNDEADJEWEL #undef P_WSTONES #undef P_BSTONES #undef P_EMBERSKEY #undef P_BRONZEKEY #undef P_DENORIAN #undef P_OPALHELMET #undef P_OPALSHIELD #undef P_IRONKEY #undef P_OPALBAND #undef P_OPALARMOUR #undef P_CAVEKEY #undef P_TALK_TSORIN #undef P_TALKOLDMAN return 1; }