To sdf
This commit is contained in:
parent
613ed97bdb
commit
2440c561f2
2
.replit
2
.replit
@ -61,7 +61,7 @@ type = "cppdbg"
|
|||||||
[languages]
|
[languages]
|
||||||
|
|
||||||
[languages.cpp]
|
[languages.cpp]
|
||||||
pattern = "**/*.{cpp,h}"
|
pattern = "**/*.{cpp,hpp}"
|
||||||
|
|
||||||
[languages.cpp.languageServer]
|
[languages.cpp.languageServer]
|
||||||
start = "ccls"
|
start = "ccls"
|
||||||
|
@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### added
|
||||||
|
|
||||||
|
- triggers
|
||||||
|
- building unlocking
|
||||||
|
|
||||||
## [0.0.1_2] 2024-08-07
|
## [0.0.1_2] 2024-08-07
|
||||||
|
|
||||||
### fixed
|
### fixed
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
{ pkgs }: {
|
{ pkgs }: {
|
||||||
deps = [
|
deps = [
|
||||||
|
pkgs.fuse-emulator
|
||||||
|
pkgs.kmod
|
||||||
|
pkgs.sshfs
|
||||||
|
pkgs.openssh
|
||||||
pkgs.clang
|
pkgs.clang
|
||||||
pkgs.ccls
|
pkgs.ccls
|
||||||
pkgs.gdb
|
pkgs.gdb
|
||||||
|
@ -20,8 +20,8 @@ namespace CMD {
|
|||||||
typedef void (*UpdateFunction)(void);
|
typedef void (*UpdateFunction)(void);
|
||||||
using Onzero = UpdateFunction;
|
using Onzero = UpdateFunction;
|
||||||
|
|
||||||
typedef bool (*Condition)(std::vector<str>);
|
typedef bool (*Condition)(std::vector<str>&);
|
||||||
typedef void (*Result)(std::vector<str>);
|
typedef void (*Result)(std::vector<str>&);
|
||||||
|
|
||||||
str name = "CMD:\\";
|
str name = "CMD:\\";
|
||||||
|
|
||||||
|
@ -5,31 +5,25 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace GRP {
|
namespace GRP {
|
||||||
using integer = mpz_class;
|
mpq_class pow(mpq_class base, mpz_class exp) {
|
||||||
using flat = mpf_class;
|
mpq_class result = 1;
|
||||||
using number = mpq_class;
|
for (mpz_class i = 0; i < exp; i++)
|
||||||
|
|
||||||
using str = std::string;
|
|
||||||
|
|
||||||
number pow(number base, integer exp) {
|
|
||||||
number result = 1;
|
|
||||||
for (integer i = 0; i < exp; i++)
|
|
||||||
result *= base;
|
result *= base;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
integer precision;
|
mpz_class precision;
|
||||||
integer kilo = 1'000;
|
mpz_class kilo = 1'000;
|
||||||
|
|
||||||
std::vector<str> formatLong = {" thousand"," million"," billion"," trillion"," quadrillion"," quintillion"," sextillion"," septillion"," octillion"," nonillion"};
|
std::vector<std::string> formatLong = {" thousand"," million"," billion"," trillion"," quadrillion"," quintillion"," sextillion"," septillion"," octillion"," nonillion"};
|
||||||
std::vector<str> prefixes = {"","un","duo","tre","quattuor","quin","sex","septen","octo","novem"};
|
std::vector<std::string> prefixes = {"","un","duo","tre","quattuor","quin","sex","septen","octo","novem"};
|
||||||
std::vector<str> suffixes = {"decillion","vigintillion","trigintillion","quadragintillion","quinquagintillion","sexagintillion","septuagintillion","octogintillion","nonagintillion"};
|
std::vector<std::string> suffixes = {"decillion","vigintillion","trigintillion","quadragintillion","quinquagintillion","sexagintillion","septuagintillion","octogintillion","nonagintillion"};
|
||||||
|
|
||||||
integer round(number x) {
|
mpz_class round(mpq_class x) {
|
||||||
return x.get_num() / x.get_den();
|
return x.get_num() / x.get_den();
|
||||||
}
|
}
|
||||||
|
|
||||||
str toString(number x) {
|
std::string toString(mpq_class x) {
|
||||||
std::stringstream result;
|
std::stringstream result;
|
||||||
if (x >= 1'000'000) {
|
if (x >= 1'000'000) {
|
||||||
size_t suffix = 1;
|
size_t suffix = 1;
|
||||||
@ -43,13 +37,13 @@ namespace GRP {
|
|||||||
suffix++;
|
suffix++;
|
||||||
}
|
}
|
||||||
|
|
||||||
integer big = round(x / kilo);
|
mpz_class big = round(x / kilo);
|
||||||
integer small = round(x - big * kilo);
|
mpz_class small = round(x - big * kilo);
|
||||||
|
|
||||||
if(small == 0) {
|
if(small == 0) {
|
||||||
result << big << formatLong[suffix];
|
result << big << formatLong[suffix];
|
||||||
} else {
|
} else {
|
||||||
str sml = small.get_str();
|
std::string sml = small.get_str();
|
||||||
char smallf[] = "000";
|
char smallf[] = "000";
|
||||||
for(int i = 0; i < sml.length(); i++) {
|
for(int i = 0; i < sml.length(); i++) {
|
||||||
smallf[2 - i] = sml[sml.length() - i - 1];
|
smallf[2 - i] = sml[sml.length() - i - 1];
|
||||||
@ -64,14 +58,14 @@ namespace GRP {
|
|||||||
return result.str();
|
return result.str();
|
||||||
} else {
|
} else {
|
||||||
x *= 10;
|
x *= 10;
|
||||||
integer big = round(x/10);
|
mpz_class big = round(x/10);
|
||||||
|
|
||||||
integer small = round(x - big * 10);
|
mpz_class small = round(x - big * 10);
|
||||||
|
|
||||||
integer kilos = big / kilo;
|
mpz_class kilos = big / kilo;
|
||||||
integer ones = big - kilos * kilo;
|
mpz_class ones = big - kilos * kilo;
|
||||||
if(kilos > 0) {
|
if(kilos > 0) {
|
||||||
str oness = ones.get_str();
|
std::string oness = ones.get_str();
|
||||||
char onesf[] = "000";
|
char onesf[] = "000";
|
||||||
for(size_t i = 0; i < oness.length(); i++) {
|
for(size_t i = 0; i < oness.length(); i++) {
|
||||||
onesf[2 - i] = oness[oness.length() - i - 1];
|
onesf[2 - i] = oness[oness.length() - i - 1];
|
||||||
@ -89,7 +83,7 @@ namespace GRP {
|
|||||||
return "error: HOW!";
|
return "error: HOW!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(integer precision = 1) {
|
void init(mpz_class precision = 1) {
|
||||||
precision = pow(precision, 10);
|
precision = pow(precision, 10);
|
||||||
|
|
||||||
for(int i = 0; i < suffixes.size(); i++) {
|
for(int i = 0; i < suffixes.size(); i++) {
|
||||||
|
110
👨💻/main.cpp
110
👨💻/main.cpp
@ -49,14 +49,24 @@ enum Buildings {
|
|||||||
struct TclickerSave {
|
struct TclickerSave {
|
||||||
number transistorBalance;
|
number transistorBalance;
|
||||||
number totalTransistors;
|
number totalTransistors;
|
||||||
/*number ascentionLevels;
|
/*integer ascensionCount;
|
||||||
|
number ascentionLevels;
|
||||||
number heavenlyMicrochips;*/
|
number heavenlyMicrochips;*/
|
||||||
integer clicks;
|
integer clicks;
|
||||||
integer cusors, moss, smallFABs, mediumFABs, largeFABs;
|
integer cusors, moss, smallFABs, mediumFABs, largeFABs;
|
||||||
//integer i860s, startups, oakTrees;
|
//integer i860s, startups, oakTrees;
|
||||||
|
bool cursorUnlocked, mossUnlocked, smallFABUnlocked, mediumFABUnlocked, largeFABUnlocked;
|
||||||
|
//bool i860Unlocked, startupUnlocked, oakTreeUnlocked;
|
||||||
};
|
};
|
||||||
|
|
||||||
TclickerSave save = {0, 0, 0, 0, 0, 0, 0, 0};
|
struct Trigger {
|
||||||
|
CMD::Condition condition;
|
||||||
|
CMD::Result result;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<Trigger> triggers;
|
||||||
|
|
||||||
|
TclickerSave save = {0, 0, 0, 0, 0, 0, 0, 0, false, false, false, false, false};
|
||||||
|
|
||||||
const str name = "Transistor Clicker";
|
const str name = "Transistor Clicker";
|
||||||
const str version = "0.0.1_2";
|
const str version = "0.0.1_2";
|
||||||
@ -85,6 +95,18 @@ number pow(number base, integer exponent) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addTrigger(Trigger trigger) {
|
||||||
|
triggers.push_back(trigger);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testTriggers(std::vector<str> args) {
|
||||||
|
for(Trigger trigger : triggers) {
|
||||||
|
if(trigger.condition(args)) {
|
||||||
|
trigger.result(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
number expandPrice(number price, integer count) {
|
number expandPrice(number price, integer count) {
|
||||||
return price * pow(expantionFactor, count);
|
return price * pow(expantionFactor, count);
|
||||||
}
|
}
|
||||||
@ -98,6 +120,8 @@ void clear(std::vector<str>&) {
|
|||||||
printTitileCard();
|
printTitileCard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str numString(number x, str thing, str plural = "s", bool round = true, str colA = BOLDGREEN, str colB = BOLDBLUE) {}
|
||||||
|
|
||||||
str TransitorsString(number transistors, bool round = true, str colA = BOLDGREEN, str colB = BOLDBLUE) {
|
str TransitorsString(number transistors, bool round = true, str colA = BOLDGREEN, str colB = BOLDBLUE) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
if(round) transistors = GRP::round(transistors);
|
if(round) transistors = GRP::round(transistors);
|
||||||
@ -106,6 +130,46 @@ str TransitorsString(number transistors, bool round = true, str colA = BOLDGREEN
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unlockCursor(std::vector<str>& args) {
|
||||||
|
save.cursorUnlocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlockMoss(std::vector<str>& args) {
|
||||||
|
save.mossUnlocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlockSmallFAB(std::vector<str>& args) {
|
||||||
|
save.smallFABUnlocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlockMediumFAB(std::vector<str>& args) {
|
||||||
|
save.mediumFABUnlocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlockLargeFAB(std::vector<str>& args) {
|
||||||
|
save.largeFABUnlocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isCursorUnLocked(std::vector<str>& args) {
|
||||||
|
return save.totalTransistors > cursorPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMossUnLocked(std::vector<str>& args) {
|
||||||
|
return save.totalTransistors > mossPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSmallFABUnLocked(std::vector<str>& args) {
|
||||||
|
return save.totalTransistors > smallFABPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMediumFABUnLocked(std::vector<str>& args) {
|
||||||
|
return save.totalTransistors > mediumFABprice;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isLargeFABUnLocked(std::vector<str>& args) {
|
||||||
|
return save.totalTransistors > largeFABPrice;
|
||||||
|
}
|
||||||
|
|
||||||
void increaseTransistors(number by) {
|
void increaseTransistors(number by) {
|
||||||
save.transistorBalance += by;
|
save.transistorBalance += by;
|
||||||
save.totalTransistors += by;
|
save.totalTransistors += by;
|
||||||
@ -145,6 +209,7 @@ number calcTPS() {
|
|||||||
void onTick() {
|
void onTick() {
|
||||||
number TPS = calcTPS();
|
number TPS = calcTPS();
|
||||||
increaseTransistors(TPS / 16);
|
increaseTransistors(TPS / 16);
|
||||||
|
testTriggers(CMD::arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onExit(std::vector<str>&) {
|
void onExit(std::vector<str>&) {
|
||||||
@ -169,7 +234,8 @@ void balance(std::vector<str>& args) {
|
|||||||
number producing;
|
number producing;
|
||||||
number TPS = calcTPS();
|
number TPS = calcTPS();
|
||||||
number basePrice;
|
number basePrice;
|
||||||
str buildingName;
|
str buildingName = args[1];
|
||||||
|
bool unlocked;
|
||||||
|
|
||||||
args[1] = tolower(args[1]);
|
args[1] = tolower(args[1]);
|
||||||
|
|
||||||
@ -184,44 +250,52 @@ void balance(std::vector<str>& args) {
|
|||||||
count = save.cusors;
|
count = save.cusors;
|
||||||
producing = calcCursorYeild();
|
producing = calcCursorYeild();
|
||||||
basePrice = cursorPrice;
|
basePrice = cursorPrice;
|
||||||
|
unlocked = save.cursorUnlocked;
|
||||||
break;
|
break;
|
||||||
case moss:
|
case moss:
|
||||||
buildingName = "moss";
|
buildingName = "moss";
|
||||||
count = save.moss;
|
count = save.moss;
|
||||||
producing = calcMossYeild();
|
producing = calcMossYeild();
|
||||||
basePrice = mossPrice;
|
basePrice = mossPrice;
|
||||||
|
unlocked = save.mossUnlocked;
|
||||||
break;
|
break;
|
||||||
case smallFAB:
|
case smallFAB:
|
||||||
buildingName = "small FAB";
|
buildingName = "small FAB";
|
||||||
count = save.smallFABs;
|
count = save.smallFABs;
|
||||||
producing = calcSmallFABYeild();
|
producing = calcSmallFABYeild();
|
||||||
basePrice = smallFABPrice;
|
basePrice = smallFABPrice;
|
||||||
|
unlocked = save.smallFABUnlocked;
|
||||||
break;
|
break;
|
||||||
case mediumFAB:
|
case mediumFAB:
|
||||||
buildingName = "medium FAB";
|
buildingName = "medium FAB";
|
||||||
count = save.mediumFABs;
|
count = save.mediumFABs;
|
||||||
producing = calcMediumFABYeild();
|
producing = calcMediumFABYeild();
|
||||||
basePrice = mediumFABprice;
|
basePrice = mediumFABprice;
|
||||||
|
unlocked = save.mediumFABUnlocked;
|
||||||
break;
|
break;
|
||||||
case largeFAB:
|
case largeFAB:
|
||||||
buildingName = "large FAB";
|
buildingName = "large FAB";
|
||||||
count = save.largeFABs;
|
count = save.largeFABs;
|
||||||
producing = calcLargeFABYeild();
|
producing = calcLargeFABYeild();
|
||||||
basePrice = largeFABPrice;
|
basePrice = largeFABPrice;
|
||||||
|
unlocked = save.largeFABUnlocked;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cout << BOLDRED << "Unknown building!\n";
|
unlocked = false;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!unlocked) {
|
||||||
|
std::cout << BOLDRED << "Unknown building!\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(count > 0) {
|
if(count > 0) {
|
||||||
yeild = producing / count;
|
yeild = producing / count;
|
||||||
|
|
||||||
integer thousandthsOfTPS = toInt((yeild * count / TPS) * 1000);
|
number percent = producing / TPS * 100;
|
||||||
number percent = thousandthsOfTPS / 10;
|
|
||||||
|
|
||||||
std::cout << BOLDBLUE << "You have " << BOLDGREEN << count << BOLDBLUE << ' ' << buildingName << "s, each producing " << TransitorsString(yeild) << " per second.\n";
|
std::cout << BOLDBLUE << "You have " << BOLDGREEN << count << BOLDBLUE << ' ' << buildingName << "s, each producing " << TransitorsString(yeild) << " per second.\n";
|
||||||
std::cout << "which produces " << TransitorsString(producing) << " per second in total which accounts for " << BOLDGREEN << percent << "%" << BOLDBLUE << " of your total TPS.\n";
|
std::cout << "which produces " << TransitorsString(producing, false) << " per second in total which accounts for " << BOLDGREEN << GRP::toString(percent) << "%" << BOLDBLUE << " of your total TPS.\n";
|
||||||
std::cout << "One " << buildingName << " would cost " << TransitorsString(expandPrice(basePrice, count)) << ".\n";
|
std::cout << "One " << buildingName << " would cost " << TransitorsString(expandPrice(basePrice, count)) << ".\n";
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -252,38 +326,48 @@ void buy(std::vector<str>& args) {
|
|||||||
str buildingName;
|
str buildingName;
|
||||||
number basePrice;
|
number basePrice;
|
||||||
integer* countPtr = nullptr;
|
integer* countPtr = nullptr;
|
||||||
|
bool buildingUnlocked = false;
|
||||||
|
|
||||||
switch(hash(building)) {
|
switch(hash(building)) {
|
||||||
case cursor:
|
case cursor:
|
||||||
buildingName = "cursor";
|
buildingName = "cursor";
|
||||||
basePrice = cursorPrice;
|
basePrice = cursorPrice;
|
||||||
countPtr = &save.cusors;
|
countPtr = &save.cusors;
|
||||||
|
buildingUnlocked = save.cursorUnlocked;
|
||||||
break;
|
break;
|
||||||
case moss:
|
case moss:
|
||||||
buildingName = "moss";
|
buildingName = "moss";
|
||||||
basePrice = mossPrice;
|
basePrice = mossPrice;
|
||||||
countPtr = &save.moss;
|
countPtr = &save.moss;
|
||||||
|
buildingUnlocked = save.mossUnlocked;
|
||||||
break;
|
break;
|
||||||
case smallFAB:
|
case smallFAB:
|
||||||
buildingName = "small FAB";
|
buildingName = "small FAB";
|
||||||
basePrice = smallFABPrice;
|
basePrice = smallFABPrice;
|
||||||
countPtr = &save.smallFABs;
|
countPtr = &save.smallFABs;
|
||||||
|
buildingUnlocked = save.smallFABUnlocked;
|
||||||
break;
|
break;
|
||||||
case mediumFAB:
|
case mediumFAB:
|
||||||
buildingName = "medium FAB";
|
buildingName = "medium FAB";
|
||||||
basePrice = mediumFABprice;
|
basePrice = mediumFABprice;
|
||||||
countPtr = &save.mediumFABs;
|
countPtr = &save.mediumFABs;
|
||||||
|
buildingUnlocked = save.mediumFABUnlocked;
|
||||||
break;
|
break;
|
||||||
case largeFAB:
|
case largeFAB:
|
||||||
buildingName = "large FAB";
|
buildingName = "large FAB";
|
||||||
basePrice = largeFABPrice;
|
basePrice = largeFABPrice;
|
||||||
countPtr = &save.largeFABs;
|
countPtr = &save.largeFABs;
|
||||||
|
buildingUnlocked = save.largeFABUnlocked;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cout << BOLDRED << "Unknown building!\n";
|
buildingUnlocked = false;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!buildingUnlocked) {
|
||||||
|
std::cout << BOLDRED << "Unknown building!\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
integer& count = *countPtr;
|
integer& count = *countPtr;
|
||||||
|
|
||||||
if(args.size() >= 2) {
|
if(args.size() >= 2) {
|
||||||
@ -415,6 +499,12 @@ int main() {
|
|||||||
CMD::addcommand("clear", clear);
|
CMD::addcommand("clear", clear);
|
||||||
CMD::addcommand("help", help);
|
CMD::addcommand("help", help);
|
||||||
|
|
||||||
|
addTrigger({isCursorUnLocked, unlockCursor});
|
||||||
|
addTrigger({isMossUnLocked, unlockMoss});
|
||||||
|
addTrigger({isSmallFABUnLocked, unlockSmallFAB});
|
||||||
|
addTrigger({isMediumFABUnLocked, unlockMediumFAB});
|
||||||
|
addTrigger({isLargeFABUnLocked, unlockLargeFAB});
|
||||||
|
|
||||||
CMD::log("Program iniitialized");
|
CMD::log("Program iniitialized");
|
||||||
|
|
||||||
CMD::runcomm("clear", click);
|
CMD::runcomm("clear", click);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user