This commit is contained in:
moganda12 2024-08-08 14:32:31 +00:00
parent 613ed97bdb
commit 2440c561f2
6 changed files with 134 additions and 39 deletions

View File

@ -61,7 +61,7 @@ type = "cppdbg"
[languages]
[languages.cpp]
pattern = "**/*.{cpp,h}"
pattern = "**/*.{cpp,hpp}"
[languages.cpp.languageServer]
start = "ccls"

View File

@ -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/)
## [Unreleased]
### added
- triggers
- building unlocking
## [0.0.1_2] 2024-08-07
### fixed

View File

@ -1,5 +1,9 @@
{ pkgs }: {
deps = [
pkgs.fuse-emulator
pkgs.kmod
pkgs.sshfs
pkgs.openssh
pkgs.clang
pkgs.ccls
pkgs.gdb

View File

@ -20,8 +20,8 @@ namespace CMD {
typedef void (*UpdateFunction)(void);
using Onzero = UpdateFunction;
typedef bool (*Condition)(std::vector<str>);
typedef void (*Result)(std::vector<str>);
typedef bool (*Condition)(std::vector<str>&);
typedef void (*Result)(std::vector<str>&);
str name = "CMD:\\";

View File

@ -5,31 +5,25 @@
#include <sstream>
namespace GRP {
using integer = mpz_class;
using flat = mpf_class;
using number = mpq_class;
using str = std::string;
number pow(number base, integer exp) {
number result = 1;
for (integer i = 0; i < exp; i++)
mpq_class pow(mpq_class base, mpz_class exp) {
mpq_class result = 1;
for (mpz_class i = 0; i < exp; i++)
result *= base;
return result;
}
integer precision;
integer kilo = 1'000;
mpz_class precision;
mpz_class kilo = 1'000;
std::vector<str> 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<str> suffixes = {"decillion","vigintillion","trigintillion","quadragintillion","quinquagintillion","sexagintillion","septuagintillion","octogintillion","nonagintillion"};
std::vector<std::string> formatLong = {" thousand"," million"," billion"," trillion"," quadrillion"," quintillion"," sextillion"," septillion"," octillion"," nonillion"};
std::vector<std::string> prefixes = {"","un","duo","tre","quattuor","quin","sex","septen","octo","novem"};
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();
}
str toString(number x) {
std::string toString(mpq_class x) {
std::stringstream result;
if (x >= 1'000'000) {
size_t suffix = 1;
@ -43,13 +37,13 @@ namespace GRP {
suffix++;
}
integer big = round(x / kilo);
integer small = round(x - big * kilo);
mpz_class big = round(x / kilo);
mpz_class small = round(x - big * kilo);
if(small == 0) {
result << big << formatLong[suffix];
} else {
str sml = small.get_str();
std::string sml = small.get_str();
char smallf[] = "000";
for(int i = 0; i < sml.length(); i++) {
smallf[2 - i] = sml[sml.length() - i - 1];
@ -64,14 +58,14 @@ namespace GRP {
return result.str();
} else {
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;
integer ones = big - kilos * kilo;
mpz_class kilos = big / kilo;
mpz_class ones = big - kilos * kilo;
if(kilos > 0) {
str oness = ones.get_str();
std::string oness = ones.get_str();
char onesf[] = "000";
for(size_t i = 0; i < oness.length(); i++) {
onesf[2 - i] = oness[oness.length() - i - 1];
@ -89,7 +83,7 @@ namespace GRP {
return "error: HOW!";
}
void init(integer precision = 1) {
void init(mpz_class precision = 1) {
precision = pow(precision, 10);
for(int i = 0; i < suffixes.size(); i++) {

View File

@ -49,14 +49,24 @@ enum Buildings {
struct TclickerSave {
number transistorBalance;
number totalTransistors;
/*number ascentionLevels;
/*integer ascensionCount;
number ascentionLevels;
number heavenlyMicrochips;*/
integer clicks;
integer cusors, moss, smallFABs, mediumFABs, largeFABs;
integer cusors, moss, smallFABs, mediumFABs, largeFABs;
//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 version = "0.0.1_2";
@ -85,6 +95,18 @@ number pow(number base, integer exponent) {
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) {
return price * pow(expantionFactor, count);
}
@ -98,6 +120,8 @@ void clear(std::vector<str>&) {
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) {
std::stringstream ss;
if(round) transistors = GRP::round(transistors);
@ -106,6 +130,46 @@ str TransitorsString(number transistors, bool round = true, str colA = BOLDGREEN
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) {
save.transistorBalance += by;
save.totalTransistors += by;
@ -145,6 +209,7 @@ number calcTPS() {
void onTick() {
number TPS = calcTPS();
increaseTransistors(TPS / 16);
testTriggers(CMD::arguments);
}
void onExit(std::vector<str>&) {
@ -169,7 +234,8 @@ void balance(std::vector<str>& args) {
number producing;
number TPS = calcTPS();
number basePrice;
str buildingName;
str buildingName = args[1];
bool unlocked;
args[1] = tolower(args[1]);
@ -184,44 +250,52 @@ void balance(std::vector<str>& args) {
count = save.cusors;
producing = calcCursorYeild();
basePrice = cursorPrice;
unlocked = save.cursorUnlocked;
break;
case moss:
buildingName = "moss";
count = save.moss;
producing = calcMossYeild();
basePrice = mossPrice;
unlocked = save.mossUnlocked;
break;
case smallFAB:
buildingName = "small FAB";
count = save.smallFABs;
producing = calcSmallFABYeild();
basePrice = smallFABPrice;
unlocked = save.smallFABUnlocked;
break;
case mediumFAB:
buildingName = "medium FAB";
count = save.mediumFABs;
producing = calcMediumFABYeild();
basePrice = mediumFABprice;
unlocked = save.mediumFABUnlocked;
break;
case largeFAB:
buildingName = "large FAB";
count = save.largeFABs;
producing = calcLargeFABYeild();
basePrice = largeFABPrice;
unlocked = save.largeFABUnlocked;
break;
default:
std::cout << BOLDRED << "Unknown building!\n";
return;
unlocked = false;
break;
}
if(!unlocked) {
std::cout << BOLDRED << "Unknown building!\n";
return;
}
if(count > 0) {
yeild = producing / count;
integer thousandthsOfTPS = toInt((yeild * count / TPS) * 1000);
number percent = thousandthsOfTPS / 10;
number percent = producing / TPS * 100;
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";
return;
} else {
@ -252,38 +326,48 @@ void buy(std::vector<str>& args) {
str buildingName;
number basePrice;
integer* countPtr = nullptr;
bool buildingUnlocked = false;
switch(hash(building)) {
case cursor:
buildingName = "cursor";
basePrice = cursorPrice;
countPtr = &save.cusors;
buildingUnlocked = save.cursorUnlocked;
break;
case moss:
buildingName = "moss";
basePrice = mossPrice;
countPtr = &save.moss;
buildingUnlocked = save.mossUnlocked;
break;
case smallFAB:
buildingName = "small FAB";
basePrice = smallFABPrice;
countPtr = &save.smallFABs;
buildingUnlocked = save.smallFABUnlocked;
break;
case mediumFAB:
buildingName = "medium FAB";
basePrice = mediumFABprice;
countPtr = &save.mediumFABs;
buildingUnlocked = save.mediumFABUnlocked;
break;
case largeFAB:
buildingName = "large FAB";
basePrice = largeFABPrice;
countPtr = &save.largeFABs;
buildingUnlocked = save.largeFABUnlocked;
break;
default:
std::cout << BOLDRED << "Unknown building!\n";
return;
buildingUnlocked = false;
break;
}
if(!buildingUnlocked) {
std::cout << BOLDRED << "Unknown building!\n";
return;
}
integer& count = *countPtr;
if(args.size() >= 2) {
@ -415,6 +499,12 @@ int main() {
CMD::addcommand("clear", clear);
CMD::addcommand("help", help);
addTrigger({isCursorUnLocked, unlockCursor});
addTrigger({isMossUnLocked, unlockMoss});
addTrigger({isSmallFABUnLocked, unlockSmallFAB});
addTrigger({isMediumFABUnLocked, unlockMediumFAB});
addTrigger({isLargeFABUnLocked, unlockLargeFAB});
CMD::log("Program iniitialized");
CMD::runcomm("clear", click);