Saving/loading files works fine and handling objects

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent c57aea3cf6
commit d1d27b8a41
  1. BIN
      C++ProjectTemplate
  2. 32
      main.cpp
  3. 1
      object.cpp
  4. 2
      save0

Binary file not shown.

@ -1474,6 +1474,9 @@ void SeasonI::keyUpdates() {
if (GetKey(F6).bPressed) {
SaveGameSaveData(0);
}
if (GetKey(F7).bPressed) {
LoadGameSaveData(0);
}
if (GetKey(O).bPressed) {
StartEffect(FOUNTAIN_EFFECT);
@ -5229,64 +5232,72 @@ void SeasonI::SaveGameSaveData(int saveSlot) {
int SeasonI::ReadIntFromStream(std::ifstream&f) {
int temp;
f>>temp;
printf("READ %d\n",temp);
return temp;
};
float SeasonI::ReadFloatFromStream(std::ifstream&f) {
float temp;
f>>temp;
printf("READ %f\n",temp);
return temp;
};
double SeasonI::ReadDoubleFromStream(std::ifstream&f) {
double temp;
f>>temp;
printf("READ %lf\n",temp);
return temp;
};
std::string SeasonI::ReadStringFromStream(std::ifstream&f) {
std::string temp;
f>>temp;
printf("READ %s\n",temp.c_str());
return temp;
};
void SeasonI::LoadGameSaveData(int saveSlot) {
std::ifstream file("save"+std::to_string(saveSlot));
std::array<vd2d,4> positions={vd2d{0,0}};
int playerCount=0;
for (int i=PLAYER;i<7;i++) {
PARTY_MEMBER_STATS[i]->_SetDirectHP(ReadIntFromStream(file));
PARTY_MEMBER_STATS[i]->stats.maxHP=ReadIntFromStream(file);
std::string memberName=ReadStringFromStream(file);
if (PARTY_MEMBER_STATS[i]->obj!=nullptr) {
PARTY_MEMBER_STATS[i]->obj->name=ReadStringFromStream(file);
PARTY_MEMBER_STATS[i]->obj->name=memberName;
}
PARTY_MEMBER_STATS[i]->_SetDirectPP(ReadIntFromStream(file));
PARTY_MEMBER_STATS[i]->stats.maxPP=ReadIntFromStream(file);
PARTY_MEMBER_STATS[i]->stats.baseAtk=ReadIntFromStream(file);
PARTY_MEMBER_STATS[i]->stats.speed=ReadIntFromStream(file);
int resistanceSize = ReadIntFromStream(file);
for (int i=0;i<resistanceSize;i++) {
PARTY_MEMBER_STATS[i]->stats.resistances[i]=ReadIntFromStream(file);
for (int j=0;j<resistanceSize;j++) {
PARTY_MEMBER_STATS[i]->stats.resistances[j]=ReadIntFromStream(file);
}
PARTY_MEMBER_STATS[i]->stats.damageReduction=ReadIntFromStream(file);
PARTY_MEMBER_STATS[i]->stats.smart=ReadIntFromStream(file)?true:false;
PARTY_MEMBER_STATS[i]->stats.dumb=ReadIntFromStream(file)?true:false;
int movesetSize=ReadIntFromStream(file);
PARTY_MEMBER_STATS[i]->moveSet.clear();
for (int i=0;i<movesetSize;i++) {
for (int j=0;j<movesetSize;j++) {
PARTY_MEMBER_STATS[i]->moveSet.push_back(MOVELIST[(BattleMoveName)ReadIntFromStream(file)]);
}
int statusEffectsSize=ReadIntFromStream(file);
PARTY_MEMBER_STATS[i]->statusEffects.clear();
for (int i=0;i<statusEffectsSize;i++) {
for (int j=0;j<statusEffectsSize;j++) {
PARTY_MEMBER_STATS[i]->statusEffects[(Property)ReadIntFromStream(file)]=ReadIntFromStream(file);
}
int equipmentSize=ReadIntFromStream(file);
for (int i=0;i<equipmentSize;i++) {
for (int j=0;j<equipmentSize;j++) {
int equipID=ReadIntFromStream(file);
if (equipID!=-1) {
PARTY_MEMBER_STATS[i]->equipment[i]=ITEMLIST[(ItemName)equipID];
PARTY_MEMBER_STATS[i]->equipment[j]=ITEMLIST[(ItemName)equipID];
}
}
double xPos=ReadDoubleFromStream(file);
double yPos=ReadDoubleFromStream(file);
if (PARTY_MEMBER_STATS[i]->obj!=nullptr) {
PARTY_MEMBER_STATS[i]->obj->Move({xPos,yPos});
}
PARTY_MEMBER_STATS[i]->obj->SetPos({xPos,yPos});
positions[playerCount++]={xPos,yPos};
}
}
int inventorySize=ReadIntFromStream(file);
@ -5300,6 +5311,9 @@ void SeasonI::LoadGameSaveData(int saveSlot) {
}
CURRENT_MAP=MAPS[(MapName::Map)ReadIntFromStream(file)];
LoadMap(CURRENT_MAP);
for (int i=0;i<playerCount;i++) {
PARTY_MEMBER_OBJ[i]->SetPos(positions[i]);
}
}
#ifndef TEST_SUITE

@ -2,6 +2,7 @@
extern std::vector<Object*> OBJECTS;
//Moves an object relative to its current position.
void Object::Move(vd2d move) {
if (move.y==0) {
pos+=move;

@ -1 +1 @@
120 120 PLAYER 30 30 8 8 4 0 0 0 0 0 0 0 11 9 10 13 14 15 16 17 33 29 21 25 1 6 4 3 -1 -1 -1 343 200 120 120 NESS 30 30 8 8 4 0 0 0 0 0 0 0 6 33 34 29 30 31 32 0 3 -1 -1 -1 343 200 120 120 PAULA 30 30 8 8 4 0 0 0 0 0 0 0 6 21 22 23 24 37 38 0 3 -1 -1 -1 343 200 120 120 JEFF 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 120 120 ANNA 30 30 8 8 4 0 0 0 0 0 0 0 4 21 25 26 29 0 3 -1 -1 -1 343 200 120 120 KING 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 120 120 POO 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 67 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 8 3 3 3 10 10 10 10 12 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 2 2 2 2 2 2 5 11 512 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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