summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2ReturnStack.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-14 00:50:34 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-14 00:50:34 +0100
commit37e364b2c6cc7487a1c888d256a73e5337bb7189 (patch)
treeeaf6e857382eef16c2dd940eb4125536fbe068bd /src/T2DLL/T2ReturnStack.cpp
downloadt2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.tar.gz
t2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.zip
initial commit
Diffstat (limited to 'src/T2DLL/T2ReturnStack.cpp')
-rw-r--r--src/T2DLL/T2ReturnStack.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/T2DLL/T2ReturnStack.cpp b/src/T2DLL/T2ReturnStack.cpp
new file mode 100644
index 0000000..4c046bb
--- /dev/null
+++ b/src/T2DLL/T2ReturnStack.cpp
@@ -0,0 +1,140 @@
+#include "T2Archive.h"
+#include "T2ReturnStack.h"
+
+T2ReturnStack::T2ReturnStack() {
+ Init();
+}
+
+T2ReturnStack::~T2ReturnStack() {
+}
+
+void T2ReturnStack::Init() {
+ for (int i = 0; i < 3; i++) {
+ mEntries[i].tenant = 0;
+ mEntries[i].time = 0;
+ }
+ mCount = 0;
+}
+
+BOOL T2ReturnStack::Current(unsigned int &tenant, unsigned int &time) {
+ if (mCount > 0) {
+ tenant = mEntries[0].tenant;
+ time = mEntries[0].time;
+ return true;
+ }
+ return false;
+}
+
+BOOL T2ReturnStack::Push(unsigned int tenant, unsigned int time) {
+ if (mCount < 3) {
+ for (int i = mCount - 1; i >= 0; i--) {
+ mEntries[i + 1] = mEntries[i];
+ }
+ mCount++;
+ mEntries[0].tenant = tenant;
+ mEntries[0].time = time;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+BOOL T2ReturnStack::Pop(unsigned int &tenant, unsigned int &time) {
+ if (mCount > 0) {
+ tenant = mEntries[0].tenant;
+ time = mEntries[0].time;
+ for (int i = 1; i < mCount; i++) {
+ mEntries[i - 1] = mEntries[i];
+ }
+ mCount--;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+BOOL T2ReturnStack::IsSetTime() const {
+ BOOL result = false;
+ if (mCount > 0 && mEntries[0].time != 0)
+ result = true;
+ return result;
+}
+
+unsigned int T2ReturnStack::GetTenant() const {
+ unsigned int result = 0;
+ if (mCount > 0)
+ result = mEntries[0].tenant;
+ return result;
+}
+
+unsigned int T2ReturnStack::GetTime() const {
+ unsigned int result = 0;
+ if (mCount > 0)
+ result = mEntries[0].time;
+ return result;
+}
+
+void T2ReturnStack::SetTime(unsigned int time) {
+ if (mCount > 0)
+ mEntries[0].time = time;
+}
+
+void T2ReturnStack::DayChanged() {
+ for (int i = 0; i < mCount; i++) {
+ if (mEntries[i].time >= 1440) {
+ mEntries[i].time -= 1440;
+ } else if (mEntries[i].time > 1438) {
+ mEntries[i].time = 0;
+ }
+ }
+}
+
+BOOL T2ReturnStack::Remove(unsigned int tenant) {
+ BOOL result = false;
+
+ for (int i = 0; i < mCount; i++) {
+ if (!result) {
+ if (mEntries[i].tenant == tenant)
+ result = true;
+ } else {
+ mEntries[i - 1] = mEntries[i];
+ }
+ }
+
+ if (result)
+ mCount--;
+
+ return result;
+}
+
+void T2ReturnStack::Peek(int index, unsigned int &tenant, unsigned int &time) {
+ tenant = mEntries[index].tenant;
+ time = mEntries[index].time;
+}
+
+void T2ReturnStack::Poke(int index, unsigned int tenant, unsigned int time) {
+ mEntries[index].tenant = tenant;
+ mEntries[index].time = time;
+}
+
+void T2ReturnStack::Read(T2Archive &stream, T2TowerDoc *towerDoc) {
+ stream >> mCount;
+ for (int i = 0; i < mCount; i++) {
+ unsigned short v;
+ stream >> v;
+ mEntries[i].tenant = v;
+ stream >> v;
+ mEntries[i].time = v;
+ }
+}
+
+void T2ReturnStack::Write(T2Archive &stream) {
+ stream << mCount;
+ for (int i = 0; i < mCount; i++) {
+ unsigned short v;
+ v = mEntries[i].tenant;
+ stream << v;
+ v = mEntries[i].time;
+ stream << v;
+ }
+}