2022-06-18 16:54:40 -05:00
|
|
|
/*
|
|
|
|
Slangin'
|
|
|
|
State Management
|
|
|
|
Author: Rudis Muiznieks
|
|
|
|
License: WTFPL
|
|
|
|
*/
|
|
|
|
|
2022-06-18 00:05:30 -05:00
|
|
|
void initializeNewGame() {
|
|
|
|
sGameState = STATE_TURN_MENU;
|
2022-06-18 21:34:58 -05:00
|
|
|
pMoney = 2000;
|
2022-06-18 00:05:30 -05:00
|
|
|
pLoanAmount = 5000;
|
|
|
|
pSavingsAmount = 0;
|
|
|
|
pLocation = LOC_BRONX;
|
|
|
|
pGuns = 0;
|
|
|
|
pCapacity = 100;
|
|
|
|
pHealth = 50;
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
pInventory[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sCurrentDay = 0;
|
2022-06-19 09:37:50 -05:00
|
|
|
incrementDay(false); // start on day 1
|
2022-06-18 00:05:30 -05:00
|
|
|
}
|
|
|
|
|
2022-06-19 09:37:50 -05:00
|
|
|
void incrementDay(const bool withInterest) {
|
2022-06-18 00:05:30 -05:00
|
|
|
sCurrentDay++;
|
2022-06-18 21:34:58 -05:00
|
|
|
sAlreadyBorrowed = false;
|
2022-06-18 00:05:30 -05:00
|
|
|
|
|
|
|
// generate new drug prices
|
2022-06-18 13:20:04 -05:00
|
|
|
sDrugPrices[DRUG_COCAINE] = random(12001) + 16000;
|
|
|
|
sDrugPrices[DRUG_HEROINE] = random(7001) + 5000;
|
|
|
|
sDrugPrices[DRUG_ACID] = (random(35) + 10) * 100;
|
|
|
|
sDrugPrices[DRUG_WEED] = (random(43) + 33) * 10;
|
|
|
|
sDrugPrices[DRUG_SPEED] = (random(16) + 7) * 10;
|
|
|
|
sDrugPrices[DRUG_LUDES] = (random(5) + 1) * 10;
|
2022-06-19 09:37:50 -05:00
|
|
|
|
|
|
|
// loan and savings interest
|
|
|
|
if (withInterest) {
|
|
|
|
pLoanAmount = floor(pLoanAmount * 1.1);
|
|
|
|
pSavingsAmount = floor(pSavingsAmount * 1.06);
|
|
|
|
}
|
2022-06-18 00:05:30 -05:00
|
|
|
}
|
|
|
|
|
2022-06-18 22:55:00 -05:00
|
|
|
void newDayRandomEvent() {
|
2022-06-19 09:37:50 -05:00
|
|
|
const int eventId = 14; //random(20);
|
2022-06-18 22:55:00 -05:00
|
|
|
sPreviousGameState = STATE_TURN_MENU;
|
|
|
|
dialogSmall = false;
|
|
|
|
switch (eventId) {
|
|
|
|
case 1:
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("Rival dealers are");
|
|
|
|
dialog[1] = F("selling cheap");
|
|
|
|
dialog[2] = F("ludes!!!");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 3;
|
|
|
|
sDrugPrices[DRUG_LUDES] = 2;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
break;
|
|
|
|
case 2:
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("Weed prices have");
|
|
|
|
dialog[1] = F("bottomed out!!!");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 2;
|
|
|
|
sDrugPrices[DRUG_WEED] = 122;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
break;
|
|
|
|
case 3:
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("Pigs are selling");
|
|
|
|
dialog[1] = F("cheap heroine");
|
|
|
|
dialog[2] = F("from last week's");
|
|
|
|
dialog[3] = F("raid!!!!");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 4;
|
|
|
|
sDrugPrices[DRUG_HEROINE] = random(1150) + 850;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 5:
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("Addicts are");
|
|
|
|
dialog[1] = F("buying heroine");
|
|
|
|
dialog[2] = F("at outrageous");
|
|
|
|
dialog[3] = F("prices!!!");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 4;
|
|
|
|
sDrugPrices[DRUG_HEROINE] = random(25001) + 18000;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
case 7:
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("Pigs made a big");
|
|
|
|
dialog[1] = F("coke bust! Prices");
|
|
|
|
dialog[2] = F("are outrageous!!!!");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 3;
|
|
|
|
sDrugPrices[DRUG_COCAINE] = random(60001) + 80000;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
break;
|
|
|
|
case 8:
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("You were mugged");
|
|
|
|
dialog[1] = F("in the subway!");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 2;
|
|
|
|
pMoney = round(pMoney / 3.0) * 2;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
case 10:
|
|
|
|
case 11: {
|
|
|
|
if (playerDrugInventoryCount() >= 50) {
|
|
|
|
const int pigs = eventId == 9 ? 1 : eventId == 10 ? 3 : 4;
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("Officer Hardass and");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialog[1] = String(pigs);
|
|
|
|
dialog[1] += F(" of his deputies");
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[2] = F("are after you!");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 3;
|
|
|
|
sPreviousGameState = STATE_FIGHT_MENU;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
} else {
|
|
|
|
sGameState = STATE_TURN_MENU;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
case 13: {
|
|
|
|
if (pMoney >= 500 && playerCapacityRemaining() >= 5) {
|
|
|
|
const int x = random(3);
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("Will you buy a");
|
2022-06-18 22:55:00 -05:00
|
|
|
if (x == 0 || x == 1) {
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[1] = x == 0 ? F("baretta for") : F(".44 magnum for");
|
|
|
|
dialog[2] = F("400 dollars?");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 3;
|
|
|
|
} else {
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[1] = F("saturday night");
|
|
|
|
dialog[2] = F("special for 400");
|
|
|
|
dialog[3] = F("dollars?");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 4;
|
|
|
|
}
|
|
|
|
sGameState = STATE_BUY_GUN_DIALOG;
|
|
|
|
} else {
|
|
|
|
sGameState = STATE_TURN_MENU;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 14:
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("There's some weed");
|
|
|
|
dialog[1] = F("here that smells");
|
|
|
|
dialog[2] = F("like good stuff!!");
|
|
|
|
dialog[3] = F("Will you smoke it?");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 4;
|
|
|
|
sGameState = STATE_DO_WEED_DIALOG;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
if (pMoney >= 300) {
|
2022-06-19 09:37:50 -05:00
|
|
|
dialog[0] = F("Will you buy a new");
|
|
|
|
dialog[1] = F("trenchcoat with");
|
|
|
|
dialog[2] = F("more pockets for");
|
|
|
|
dialog[3] = F("200 bucks?");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialogLength = 4;
|
|
|
|
sGameState = STATE_BUY_COAT_DIALOG;
|
|
|
|
} else {
|
|
|
|
sGameState = STATE_TURN_MENU;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 16: {
|
|
|
|
if (playerCapacityRemaining() >= 8) {
|
|
|
|
const int amount = random(7) + 1;
|
|
|
|
const int drug = random(6);
|
|
|
|
pInventory[drug] += amount;
|
|
|
|
dialog[0] = F("You found ");
|
|
|
|
dialog[0] += String(amount);
|
|
|
|
dialog[1] = F("units of: ");
|
|
|
|
dialog[1] += lookupDrug(drug);
|
|
|
|
dialog[2] = "on a dead dude in";
|
|
|
|
dialog[3] = "the subway!!!";
|
|
|
|
dialogLength = 4;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
} else {
|
|
|
|
sGameState = STATE_TURN_MENU;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 17:
|
|
|
|
dialog[0] = "The market has";
|
|
|
|
dialog[1] = "been flooded with";
|
|
|
|
dialog[2] = "cheap homemade";
|
|
|
|
dialog[3] = "acid!!!!";
|
|
|
|
dialogLength = 4;
|
|
|
|
sDrugPrices[DRUG_ACID] = random(551) + 250;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sGameState = STATE_TURN_MENU;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 00:05:30 -05:00
|
|
|
void handleMenuAction() {
|
|
|
|
screenInitialized = false;
|
|
|
|
switch (sGameState) {
|
|
|
|
case STATE_TITLE:
|
|
|
|
switch (menuSelected) {
|
|
|
|
case 0: // new game
|
|
|
|
initializeNewGame();
|
|
|
|
break;
|
|
|
|
// TODO: continue/load saved
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_TURN_MENU:
|
2022-06-18 16:54:40 -05:00
|
|
|
sPreviousGameState = STATE_TURN_MENU;
|
2022-06-18 00:05:30 -05:00
|
|
|
switch (menuSelected) {
|
|
|
|
case 0: // trenchcoat
|
|
|
|
sGameState = STATE_INVENTORY;
|
|
|
|
break;
|
|
|
|
case 1: // buy drugs
|
2022-06-18 13:20:04 -05:00
|
|
|
sGameState = STATE_BUY_MENU;
|
|
|
|
break;
|
2022-06-18 00:05:30 -05:00
|
|
|
case 2: // sell drugs
|
2022-06-18 13:20:04 -05:00
|
|
|
sGameState = STATE_SELL_MENU;
|
|
|
|
break;
|
2022-06-18 00:05:30 -05:00
|
|
|
case 3: // jet
|
2022-06-18 13:20:04 -05:00
|
|
|
sGameState = STATE_JET_MENU;
|
|
|
|
break;
|
2022-06-18 00:05:30 -05:00
|
|
|
case 4: // loan shark
|
2022-06-18 13:20:04 -05:00
|
|
|
sGameState = STATE_SHARK_MENU;
|
|
|
|
break;
|
2022-06-18 00:05:30 -05:00
|
|
|
case 5: // bank
|
2022-06-18 13:20:04 -05:00
|
|
|
sGameState = STATE_BANK_MENU;
|
2022-06-18 00:05:30 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_JET_MENU:
|
2022-06-19 09:37:50 -05:00
|
|
|
incrementDay(true);
|
2022-06-18 22:55:00 -05:00
|
|
|
pLocation = menuSelected < pLocation ? menuSelected : menuSelected + 1;
|
|
|
|
newDayRandomEvent();
|
2022-06-18 16:54:40 -05:00
|
|
|
break;
|
2022-06-18 21:34:58 -05:00
|
|
|
|
2022-06-18 18:17:18 -05:00
|
|
|
case STATE_BUY_MENU: {
|
|
|
|
int remaining = playerCapacityRemaining();
|
2022-06-18 16:54:40 -05:00
|
|
|
sPreviousGameState = STATE_BUY_MENU;
|
|
|
|
sCurrentDrug = menuSelected;
|
2022-06-18 18:17:18 -05:00
|
|
|
if (remaining <= 0) {
|
2022-06-18 16:54:40 -05:00
|
|
|
dialog[0] = F("Oops!");
|
|
|
|
dialog[1] = F("");
|
2022-06-18 18:17:18 -05:00
|
|
|
dialog[2] = F("You can't carry");
|
2022-06-18 16:54:40 -05:00
|
|
|
dialog[3] = F("more ");
|
|
|
|
dialog[3] += lookupDrug(sCurrentDrug);
|
|
|
|
dialog[3] += F("!");
|
|
|
|
dialogLength = 4;
|
|
|
|
dialogSmall = false;
|
|
|
|
sPreviousGameState = sGameState;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
} else if (pMoney < sDrugPrices[sCurrentDrug]) {
|
|
|
|
dialog[0] = F("Oops!");
|
|
|
|
dialog[1] = F("");
|
|
|
|
dialog[2] = F("You can't afford");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialog[3] = lookupDrug(sCurrentDrug);
|
|
|
|
dialog[3] += F("!");
|
2022-06-18 16:54:40 -05:00
|
|
|
dialogLength = 4;
|
|
|
|
dialogSmall = false;
|
|
|
|
sPreviousGameState = sGameState;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
} else {
|
|
|
|
sGameState = STATE_BUY_QTY_INPUT;
|
|
|
|
sCurrentQty = 0;
|
|
|
|
sQtyMax = floor(pMoney / (float)sDrugPrices[sCurrentDrug]);
|
2022-06-18 18:17:18 -05:00
|
|
|
if (remaining < sQtyMax) sQtyMax = remaining;
|
2022-06-18 16:54:40 -05:00
|
|
|
}
|
|
|
|
break;
|
2022-06-18 18:17:18 -05:00
|
|
|
}
|
2022-06-18 21:34:58 -05:00
|
|
|
|
2022-06-18 00:05:30 -05:00
|
|
|
case STATE_SELL_MENU:
|
2022-06-18 16:54:40 -05:00
|
|
|
sPreviousGameState = STATE_SELL_MENU;
|
|
|
|
sCurrentDrug = menuSelected;
|
|
|
|
if (pInventory[sCurrentDrug] > 0) {
|
|
|
|
sGameState = STATE_SELL_QTY_INPUT;
|
|
|
|
sCurrentQty = 0;
|
|
|
|
sQtyMax = pInventory[sCurrentDrug];
|
|
|
|
} else {
|
|
|
|
dialog[0] = F("Oops!");
|
|
|
|
dialog[1] = F("");
|
|
|
|
dialog[2] = F("You don't have any");
|
2022-06-18 22:55:00 -05:00
|
|
|
dialog[3] = lookupDrug(sCurrentDrug);
|
|
|
|
dialog[3] += F("!");
|
2022-06-18 16:54:40 -05:00
|
|
|
dialogLength = 4;
|
|
|
|
dialogSmall = false;
|
|
|
|
sPreviousGameState = sGameState;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
}
|
|
|
|
break;
|
2022-06-18 21:34:58 -05:00
|
|
|
|
2022-06-18 00:05:30 -05:00
|
|
|
case STATE_SHARK_MENU:
|
2022-06-18 21:34:58 -05:00
|
|
|
sPreviousGameState = STATE_SHARK_MENU;
|
|
|
|
sCurrentQty = 0;
|
|
|
|
switch (menuSelected) {
|
|
|
|
case 0: // repay loan
|
|
|
|
sGameState = STATE_PAY_LOAN_INPUT;
|
|
|
|
sQtyMax = pLoanAmount > pMoney ? pMoney : pLoanAmount;
|
|
|
|
break;
|
|
|
|
case 1: // borrow money
|
|
|
|
if (sAlreadyBorrowed) {
|
|
|
|
dialog[0] = F("You already");
|
|
|
|
dialog[1] = F("borrowed money");
|
|
|
|
dialog[2] = F("today!");
|
|
|
|
dialogLength = 3;
|
|
|
|
dialogSmall = false;
|
|
|
|
sGameState = STATE_INFO_DIALOG;
|
|
|
|
} else {
|
|
|
|
sGameState = STATE_BORROW_INPUT;
|
|
|
|
sQtyMax = 5000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2022-06-18 00:05:30 -05:00
|
|
|
case STATE_BANK_MENU:
|
2022-06-18 21:34:58 -05:00
|
|
|
sPreviousGameState = STATE_BANK_MENU;
|
2022-06-18 22:55:00 -05:00
|
|
|
sCurrentQty = 0;
|
2022-06-18 21:34:58 -05:00
|
|
|
switch (menuSelected) {
|
|
|
|
case 0: // deposit money
|
|
|
|
sGameState = STATE_DEPOSIT_INPUT;
|
|
|
|
sQtyMax = pMoney;
|
|
|
|
break;
|
|
|
|
case 1: // withdraw money
|
|
|
|
sGameState = STATE_WITHDRAW_INPUT;
|
|
|
|
sQtyMax = pSavingsAmount;
|
|
|
|
break;
|
|
|
|
}
|
2022-06-18 00:05:30 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-18 16:54:40 -05:00
|
|
|
|
2022-06-18 18:17:18 -05:00
|
|
|
bool checkBackedOut(const bool eitherButton) {
|
|
|
|
if (arduboy.justPressed(B_BUTTON) ||
|
|
|
|
(eitherButton && arduboy.justPressed(A_BUTTON))) {
|
2022-06-18 16:54:40 -05:00
|
|
|
screenInitialized = false;
|
|
|
|
sGameState = sPreviousGameState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-18 18:17:18 -05:00
|
|
|
|
|
|
|
int playerCapacityRemaining() {
|
|
|
|
int qty = 0;
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
qty += pInventory[i];
|
|
|
|
}
|
2022-06-18 22:55:00 -05:00
|
|
|
qty += pGuns * 5;
|
2022-06-18 18:17:18 -05:00
|
|
|
return pCapacity - qty;
|
|
|
|
}
|
2022-06-18 22:55:00 -05:00
|
|
|
|
|
|
|
int playerDrugInventoryCount() {
|
|
|
|
int count = 0;
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
count += pInventory[i];
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|