Skip to content

Commit

Permalink
Changed versioning system, fixed bait
Browse files Browse the repository at this point in the history
  • Loading branch information
firefish111 committed Jun 25, 2023
1 parent ddba1b7 commit bc1fd84
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
4 changes: 2 additions & 2 deletions destruct.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (argc > 1 && strcmp(argv[1], "/d") == 0) {
printf("Gone Fishing v%zu.%zu.%zu savefile destructurer. Copyright firefish %d.\n\n", VER / 100, (VER / 10) % 10, VER % 10, YEAR);
printf("Gone Fishing v%s savefile destructurer. Copyright firefish %d.\n\n", mkver(VER), YEAR);

savefile = fopen("GONEFISH.SAV", "rb");
if (!savefile) {
Expand All @@ -9,7 +9,7 @@ if (argc > 1 && strcmp(argv[1], "/d") == 0) {

tempBuf = calloc(sizeof(size_t), LEN + 4);
fread(tempBuf, sizeof(size_t), LEN + 4, savefile);
printf("Save version %zu.%zu.%zu.\nTier %d (%s), $%d in bank, %d bait.\nFish:\n", tempBuf[0] / 100, (tempBuf[0] / 10) % 10, tempBuf[0] % 10, tempBuf[1], rodname[tempBuf[1]], tempBuf[2], tempBuf[LEN + 3]);
printf("Save version %s.\nTier %d (%s), $%d in bank, %d bait.\nFish:\n", mkver(tempBuf[0]), tempBuf[1], rodname[tempBuf[1]], tempBuf[2], tempBuf[LEN + 3]);

for (i = 0; i < LEN; ++i) {
printf("\t%zu %s,\n", tempBuf[i + 3], fish[i < 5 ? i : i + 1]);
Expand Down
44 changes: 38 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#include <conio.h> // needs this for getch() which is used instead of getchar()
#include "table.h"

// semver version; insert dots after each digit
const size_t VER = 204;
// semver version; insert dots after each nybble; max 15.15.15.rc6
// last digit is subversion - f is none, 0-3 is alpha, 4-7 is beta, 8-14 is rc1-6
const unsigned short VER = 0x2205;

unsigned char tier = 0x0;
const int LEN = 9;
Expand All @@ -24,13 +25,43 @@ FILE * savefile;
#include "cast.h"
#include "market.h"

char* verBuf;
#define VER_LEN 20

char* mkver(unsigned short ver) {
memset(verBuf, '\0', VER_LEN);
sprintf(verBuf, "%hu.%hu.%hu", (ver >> 12) & 0x000f, (ver >> 8) & 0x000f, (ver >> 4) & 0x000f);
switch ((ver & 0x000f)) {
case 15:
break;
case 0:
case 1:
case 2:
case 3:
sprintf(verBuf + strlen(verBuf), "-alpha.%d", (ver & 0x000f) + 1);
break;
case 4:
case 5:
case 6:
case 7:
sprintf(verBuf + strlen(verBuf), "-beta.%d", (ver & 0x000f) - 3);
break;
default:
sprintf(verBuf + strlen(verBuf), "-rc.%d", (ver & 0x000f) - 7);
break;
}
return verBuf;
}

int main(int argc, char** argv) {
verBuf = calloc(VER_LEN, sizeof(char));

// save destructuror
#include "destruct.h"

srand(time(NULL));

printf("Gone Fishing v%zu.%zu.%zu. Copyright @firefish %d.\nRun with /d flag to destructure the save file.\n\n", VER / 100, (VER / 10) % 10, VER % 10, YEAR);
printf("Gone Fishing v%s. Copyright @firefish %d.\nRun with /d flag to destructure the save file.\n\n", mkver(VER), YEAR);

i = access("GONEFISH.SAV", 0); // F_OK ain't defined, so we use good ol' fashioned 0
start:
Expand Down Expand Up @@ -65,7 +96,7 @@ int main(int argc, char** argv) {

// file format understander
if (tempBuf[0] > VER) {
printf("You're trying to import a save from a newer version of Gone Fishing (%zu.%zu.%zu).\n\tAre you sure you want to import? (y/N)\n", tempBuf[0] / 100, (tempBuf[0] / 10) % 10, tempBuf[0] % 10);
printf("You're trying to import a save from a newer version of Gone Fishing (%s).\n\tAre you sure you want to import? (y/N)\n", mkver(tempBuf[0]));

fflush(stdout);
choice = getch();
Expand All @@ -76,7 +107,7 @@ int main(int argc, char** argv) {
goto start;
}
} else if (tempBuf[0] < VER) {
printf("Updating save from v%zu.%zu.%zu to v%zu.%zu.%zu.\n\n", tempBuf[0] / 100, (tempBuf[0] / 10) % 10, tempBuf[0] % 10, VER / 100, (VER / 10) % 10, VER % 10);
printf("Updating save from v%s.\n\n", mkver(tempBuf[0]), mkver(VER));
}

tier = (unsigned char) tempBuf[1];
Expand Down Expand Up @@ -132,6 +163,7 @@ int main(int argc, char** argv) {

free(tempBuf);
free(data); // it's only 18 bytes but it matters
free(verBuf);
return 0;
default:
cast();
Expand All @@ -140,4 +172,4 @@ int main(int argc, char** argv) {

// how the hell did you get here
return 0;
}
}
32 changes: 20 additions & 12 deletions market.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,41 @@ int to_buy, to_sell, i;
bool unlocked = false;

void market() {


for (i = 0; i < 5; ++i) {
printf("You have %zu %s.\n", data[i], fish[i]);
if (tier >= 11) {
printf("You have %zu %s, which you can sell for $%d per piece.\n", data[i], fish[i], sale[i]);
} else {
printf("You have %zu %s.\n", data[i], fish[i]);
}
}

if (tier >= 11) {
for (i = 7; i < 11; ++i) {
printf("You have %zu %s, which you can sell for $%d per piece.\n", data[i-2], fish[i-1], sale[i-7]);
printf("You have %zu %s.\n", data[i-2], fish[i-1]);
}
}

printf("\n\nYou also have $%zu, and %zu bait.\n", money, bait);

total = floor((double) money / (double) COST);

if (money >= COST) {
printf("\nYou can buy %g bait.\nHow much bait would you like to buy? ", total);
scanf("%d", &to_buy);
if (tier >= 11) {
if (money >= COST) {
printf("\nYou can buy %g bait.\nHow much bait would you like to buy? ", total);
scanf("%d", &to_buy);

if (to_buy <= total) {
money -= to_buy * COST;
bait += to_buy;
unlocked = true;
if (to_buy <= total) {
money -= to_buy * COST;
bait += to_buy;
unlocked = true;
} else {
printf("Unfortunately, you can't afford that much bait.\n\tEither try buying less, or try selling some of your fish.\n");
}
} else {
printf("Unfortunately, you can't afford that much bait.\n\tEither try buying less, or try selling some of your fish.\n");
printf("You can't afford any bait. Bait costs $21 per piece. You currently have $%zu.\n", money);
}
} else {
printf("You can't afford any bait. Bait costs $21 per piece. You currently have $%zu.\n", money);
}

/*for (i = 5, has_some = false; i < 9; ++i) {
Expand Down

0 comments on commit bc1fd84

Please sign in to comment.