Skip to content

Commit

Permalink
Merge fix to character creation scrollbars, reading cancallation noti…
Browse files Browse the repository at this point in the history
…fication, and item initialization unification.

Conflicts:
	game.h
	item.h
  • Loading branch information
kevingranade committed Sep 6, 2013
3 parents 56eba4f + bf98c6b + 09f33a6 commit 6a49afc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 97 deletions.
10 changes: 8 additions & 2 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,15 +923,21 @@ void game::process_activity()
u.skillLevel(reading->type).exercise());

if (u.skillLevel(reading->type) == originalSkillLevel && (u.activity.continuous || query_yn(_("Study %s?"), reading->type->name().c_str()))) {
//If we just started studying, tell the player how to stop
if(!u.activity.continuous) {
add_msg(_("Now studying %s, %s to stop early."),
reading->type->name().c_str(),
press_x(ACTION_PAUSE).c_str());
}
u.cancel_activity();
if (u.activity.index == -2) {
u.read(this,u.weapon.invlet);
} else {
u.read(this,u.activity.invlet);
}
if (u.activity.type != ACT_NULL) {
u.activity.continuous = true;
return;
u.activity.continuous = true;
return;
}
}

Expand Down
3 changes: 3 additions & 0 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ extern game *g;
extern bool trigdist;
extern bool use_tiles;

extern const int savegame_version;
extern int savegame_loading_version;

enum tut_type {
TUT_NULL,
TUT_BASIC, TUT_COMBAT,
Expand Down
50 changes: 10 additions & 40 deletions gamesave.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@

#include "game.h"
#include "rng.h"
#include "input.h"
#include "keypress.h"
#include "output.h"
#include "skill.h"
#include "line.h"
#include "computer.h"
#include "veh_interact.h"
#include "options.h"
#include "auto_pickup.h"
#include "mapbuffer.h"
#include "debug.h"
#include "editmap.h"
#include "bodypart.h"
#include "map.h"
#include "output.h"
#include "uistate.h"
#include "item_factory.h"
#include "advanced_inv.h"
#include "helper.h"
#include "text_snippets.h"
#include "catajson.h"
#include "artifact.h"
#include "overmapbuffer.h"
#include "trap.h"
#include "mapdata.h"
#include "catacharset.h"
#include "translations.h"
#include <map>
#include <set>
Expand All @@ -36,25 +24,13 @@
#include <sstream>
#include <math.h>
#include <vector>
#ifndef _MSC_VER
#include <unistd.h>
#include <dirent.h>
#endif
#include <sys/stat.h>
#include "debug.h"
#include "artifactdata.h"
#include "weather.h"
#if (defined _WIN32 || defined __WIN32__)
#include <windows.h>
#include <tchar.h>
#endif

#ifdef _MSC_VER
// MSVC doesn't have c99-compatible "snprintf", so do what picojson does and use _snprintf_s instead
#define snprintf _snprintf_s
#endif

#define dbg(x) dout((DebugLevel)(x),D_GAME) << __FILE__ << ":" << __LINE__ << ": "
const int savegame_version = 4;
////
int savegame_loading_version = savegame_version;

/*
* Save to opened character.sav
Expand All @@ -64,14 +40,13 @@ void game::serialize(std::ofstream & fout) {
* save format version. If an alteration is made that breaks saves, please bump this version and
* make a new copy in serialize_load.
*/
const int savever = 3;

/*
* Format version 3: Interim format. Still resembles a hairball, but it's at least a multi-line hairball;
* Format version -current-: Interim format. Still resembles a hairball, but it's at least a multi-line hairball;
* Data is segmented for readabilty, stability, and gradual conversion into something closer to sanity.
*/
// Header
fout << "# version " << savever << std::endl;
fout << "# version " << savegame_version << std::endl;
// First, write out basic game state information.
fout << int(turn) << " " << int(last_target) << " " << int(run_mode) << " " <<
mostseen << " " << nextinv << " " << next_npc_id << " " <<
Expand Down Expand Up @@ -135,7 +110,6 @@ inline std::stringstream & stream_line(std::ifstream & f, std::stringstream & s,
* Parse an open .sav file.
*/
void game::unserialize(std::ifstream & fin) {
int loadver=0; // version to load; set by '# version n' header
if ( fin.peek() == '#' ) {
std::string vline;
getline(fin, vline);
Expand All @@ -144,16 +118,11 @@ void game::unserialize(std::ifstream & fin) {
std::stringstream vliness(vline);
vliness >> tmphash >> tmpver >> savedver;
if ( tmpver == "version" && savedver != -1 ) {
loadver = savedver;
savegame_loading_version = savedver;
}
}
switch (loadver) {
/*
case ???: {
} break;
*/
case 3:
case 2: {
switch (savegame_loading_version) {
default: {
/*
* Format version 3: Temporary format. Still resembles a hairball, but it's at least a multi-line hairball;
* Data is segmented for readabilty, stability, and gradual conversion into something closer to sanity.
Expand Down Expand Up @@ -269,7 +238,8 @@ void game::unserialize(std::ifstream & fin) {
////////
} break;

default: {
case 0: {
// todo: make savegame_legacy.cpp?
/*
original 'structure', which globs game/weather/location & killcount/player data onto the same lines.
*/
Expand Down
81 changes: 26 additions & 55 deletions item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,18 @@ std::string default_technique_name(technique_id tech);

item::item()
{
name = "";
charges = -1;
bday = 0;
invlet = 0;
damage = 0;
burnt = 0;
poison = 0;
mode = "NULL";
item_counter = 0;
type = nullitem();
curammo = NULL;
corpse = NULL;
active = false;
owned = -1;
mission_id = -1;
player_id = -1;
init();
}

item::item(itype* it, unsigned int turn)
{
init();
if(!it)
type = nullitem();
else
type = it;
bday = turn;
name = "";
invlet = 0;
damage = 0;
burnt = 0;
poison = 0;
mode = "NULL";
item_counter = 0;
active = false;
curammo = NULL;
corpse = it->corpse;
owned = -1;
mission_id = -1;
player_id = -1;
if (it == NULL)
return;
name = it->name;
Expand Down Expand Up @@ -100,6 +74,7 @@ item::item(itype* it, unsigned int turn)

item::item(itype *it, unsigned int turn, char let)
{
init();
if(!it) {
type = nullitem();
debugmsg("Instantiating an item from itype, with NULL itype!");
Expand All @@ -108,12 +83,6 @@ item::item(itype *it, unsigned int turn, char let)
}
bday = turn;
name = it->name;
damage = 0;
burnt = 0;
poison = 0;
mode = "NULL";
item_counter = 0;
active = false;
if (it->is_gun()) {
charges = 0;
} else if (it->is_ammo()) {
Expand Down Expand Up @@ -155,15 +124,7 @@ item::item(itype *it, unsigned int turn, char let)

void item::make_corpse(itype* it, mtype* mt, unsigned int turn)
{
name = "";
charges = -1;
invlet = 0;
damage = 0;
burnt = 0;
poison = 0;
mode = "NULL";
item_counter = 0;
curammo = NULL;
init();
active = mt->species == species_zombie ? true : false;
if(!it)
type = nullitem();
Expand All @@ -188,8 +149,28 @@ item::~item()
{
}

void item::init() {
name = "";
charges = -1;
bday = 0;
invlet = 0;
damage = 0;
burnt = 0;
poison = 0;
mode = "NULL";
item_counter = 0;
type = nullitem();
curammo = NULL;
corpse = NULL;
active = false;
owned = -1;
mission_id = -1;
player_id = -1;
}

void item::make(itype* it)
{
init();
if(!it)
type = nullitem();
else
Expand All @@ -201,6 +182,7 @@ void item::clear()
{
// should we be clearing contents, as well?
// Seems risky to - there aren't any reported content-clearing bugs
// init(); // this seems to fit? But above comment..
item_tags.clear();
item_vars.clear();
}
Expand Down Expand Up @@ -455,21 +437,10 @@ bool itag2ivar( std::string &item_tag, std::map<std::string, std::string> &item_

bool item::json_load(picojson::value parsed, game * g)
{
init();
clear();
const picojson::object &data = parsed.get<picojson::object>();


burnt = 0;
owned = -1;
poison = 0;
mode = "NULL";
owned = -1;
mission_id = -1;
player_id = -1;
name = "";
active = false;


std::string idtmp="";
std::string ammotmp="null";
int lettmp = 0;
Expand Down
1 change: 1 addition & 0 deletions item.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class item
void make_corpse(itype* it, mtype* mt, unsigned int turn); // Corpse
item(std::string itemdata, game *g);
virtual ~item();
void init();
void make(itype* it);
void clear(); // cleanup that's required to re-use an item variable

Expand Down

0 comments on commit 6a49afc

Please sign in to comment.