From 8841c3a25e9bd54883467a27fc999b565a979669 Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Sun, 19 Jun 2022 10:37:16 -0500 Subject: [PATCH] drug prices were overflowing ints, changed to long --- lookups.ino | 37 -------------------------------- menu.ino | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ slangin.ino | 43 ++++++------------------------------- states.ino | 13 ++++++----- 4 files changed, 75 insertions(+), 80 deletions(-) delete mode 100644 lookups.ino diff --git a/lookups.ino b/lookups.ino deleted file mode 100644 index 65337a0..0000000 --- a/lookups.ino +++ /dev/null @@ -1,37 +0,0 @@ -String lookupLocation(GameLocation loc) { - switch (loc) { - case LOC_BRONX: - return F("Bronx"); - case LOC_GHETTO: - return F("Ghetto"); - case LOC_CENTRAL_PARK: - return F("Central Park"); - case LOC_MANHATTEN: - return F("Manhatten"); - case LOC_CONEY_ISLAND: - return F("Coney Island"); - case LOC_BROOKLYN: - return F("Brooklyn"); - default: - return F(""); - } -} - -String lookupDrug(Drug drug) { - switch (drug) { - case DRUG_COCAINE: - return F("Cocaine"); - case DRUG_HEROINE: - return F("Heroine"); - case DRUG_ACID: - return F("Acid"); - case DRUG_WEED: - return F("Weed"); - case DRUG_SPEED: - return F("Speed"); - case DRUG_LUDES: - return F("Ludes"); - default: - return F(""); - } -} diff --git a/menu.ino b/menu.ino index 9e38d63..5369740 100644 --- a/menu.ino +++ b/menu.ino @@ -10,6 +10,44 @@ const uint8_t PROGMEM spriteMenuCursor[] = { 0x1f, 0x0e, 0x04, }; +String lookupLocation(GameLocation loc) { + switch (loc) { + case LOC_BRONX: + return F("Bronx"); + case LOC_GHETTO: + return F("Ghetto"); + case LOC_CENTRAL_PARK: + return F("Central Park"); + case LOC_MANHATTEN: + return F("Manhatten"); + case LOC_CONEY_ISLAND: + return F("Coney Island"); + case LOC_BROOKLYN: + return F("Brooklyn"); + default: + return F(""); + } +} + +String lookupDrug(Drug drug) { + switch (drug) { + case DRUG_COCAINE: + return F("Cocaine"); + case DRUG_HEROINE: + return F("Heroine"); + case DRUG_ACID: + return F("Acid"); + case DRUG_WEED: + return F("Weed"); + case DRUG_SPEED: + return F("Speed"); + case DRUG_LUDES: + return F("Ludes"); + default: + return F(""); + } +} + void computeMenuSizes(const bool small, const bool cols, const int itemCount, const String items[], int& x1, int& x2, int& y) { @@ -98,3 +136,27 @@ void drawMenuIndicator(const int menuSelected, const bool small, Sprites::drawOverwrite(cx - 4, cy + (small ? 1 : 2), spriteMenuCursor, 0); } } + +void buildDrugMenu(const long extra[6]) { + int lengths[6]; + int col1Max = 0; + int col2Max = 0; + for (int i = 0; i < 6; i++) { + int extraLen = String(extra[i]).length(); + lengths[i] = lookupDrug(i).length() + 1 + extraLen; + if (i < 3 && lengths[i] > col1Max) col1Max = lengths[i]; + if (i >= 3 && lengths[i] > col2Max) col2Max = lengths[i]; + } + for (int i = 0; i < 6; i++) { + const int colMax = i < 3 ? col1Max : col2Max; + menu[i] = lookupDrug(i); + menu[i] += F(" "); + for (int s = 0; s < colMax - lengths[i]; s++) { + menu[i] += F(" "); + } + menu[i] += String(extra[i]); + } + menuLength = 6; + menuCols = true; + menuSmall = col1Max + col2Max > 22; +} diff --git a/slangin.ino b/slangin.ino index 5c82766..a2b2408 100644 --- a/slangin.ino +++ b/slangin.ino @@ -73,7 +73,7 @@ bool screenInitialized; GameState sGameState; GameState sPreviousGameState; int sCurrentDay; -int sDrugPrices[6]; +long sDrugPrices[6]; int sCurrentDrug; long sCurrentQty; long sQtyMax; @@ -91,7 +91,7 @@ GameLocation pLocation; int pGuns; int pCapacity; int pHealth; -int pInventory[6]; +long pInventory[6]; String menu[8]; int menuLength = 0; @@ -142,9 +142,9 @@ void loop() { case STATE_TURN_MENU: drawStatusBar(); drawTitle(lookupLocation(pLocation)); - menu[0] = F("Trenchcoat"); - menu[1] = F("Buy Drugs"); - menu[2] = F("Sell Drugs"); + menu[0] = F("Buy Drugs"); + menu[1] = F("Sell Drugs"); + menu[2] = F("Trenchcoat"); menu[3] = F("Jet"); if (pLocation == LOC_BRONX) { menu[4] = F("Loan Shark"); @@ -508,7 +508,7 @@ void loop() { void drawStatusBar() { if (sGameState == STATE_INVENTORY) { const int remaining = playerCapacityRemaining(); - const int chars = numberChars(remaining); + const int chars = String(remaining).length(); const int x = 128 - ((chars + 9) * 4); font3x5.setCursor(1, 0); font3x5.print(F("Guns ")); @@ -517,7 +517,7 @@ void drawStatusBar() { font3x5.print(F("Capacity ")); font3x5.print(remaining); } else { - const int chars = numberChars(pMoney); + const int chars = String(pMoney).length(); const int x = 128 - (chars * 4); if (sGameState == STATE_SHARK_MENU || sGameState == STATE_BANK_MENU) { font3x5.setCursor(1, 0); @@ -543,35 +543,6 @@ void drawTitle(const String title) { font4x6.print(title); } -void buildDrugMenu(int extra[6]) { - int lengths[6]; - int col1Max = 0; - int col2Max = 0; - for (int i = 0; i < 6; i++) { - int extraLen = numberChars(extra[i]); - lengths[i] = lookupDrug(i).length() + 1 + extraLen; - if (i < 3 && lengths[i] > col1Max) col1Max = lengths[i]; - if (i >= 3 && lengths[i] > col2Max) col2Max = lengths[i]; - } - for (int i = 0; i < 6; i++) { - int colMax = i < 3 ? col1Max : col2Max; - menu[i] = lookupDrug(i) + F(" "); - for (int s = 0; s < colMax - lengths[i]; s++) { - menu[i] += F(" "); - } - menu[i] += extra[i]; - } - menuLength = 6; - menuCols = true; - menuSmall = col1Max + col2Max > 22; -} - -int numberChars(long num) { - int length = 1; - while (num /= 10) length++; - return length; -} - void drawDialog() { arduboy.drawRoundRect(0, 0, 128, 64, 5, WHITE); if (dialogSmall) { diff --git a/states.ino b/states.ino index a529e32..ae678c3 100644 --- a/states.ino +++ b/states.ino @@ -43,7 +43,7 @@ void incrementDay(const bool withInterest) { } void newDayRandomEvent() { - const int eventId = 14; //random(20); + const int eventId = 6; //random(20); sPreviousGameState = STATE_TURN_MENU; dialogSmall = false; switch (eventId) { @@ -196,22 +196,21 @@ void handleMenuAction() { case 0: // new game initializeNewGame(); break; - // TODO: continue/load saved } break; case STATE_TURN_MENU: sPreviousGameState = STATE_TURN_MENU; switch (menuSelected) { - case 0: // trenchcoat - sGameState = STATE_INVENTORY; - break; - case 1: // buy drugs + case 0: // buy drugs sGameState = STATE_BUY_MENU; break; - case 2: // sell drugs + case 1: // sell drugs sGameState = STATE_SELL_MENU; break; + case 2: // trenchcoat + sGameState = STATE_INVENTORY; + break; case 3: // jet sGameState = STATE_JET_MENU; break;