aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeFiles/sdl_test.dir/CXX.includecache420
-rw-r--r--CMakeFiles/sdl_test.dir/depend.internal1
-rw-r--r--CMakeFiles/sdl_test.dir/depend.make1
-rw-r--r--CMakeFiles/sdl_test.dir/game/ground.cpp.objbin184139 -> 367258 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/game/gst.cpp.objbin166407 -> 538957 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/game/load.cpp.objbin2113607 -> 2262664 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/game/menu.cpp.objbin182045 -> 182115 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/game/playercontrol.cpp.objbin443933 -> 529811 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/game/tech.cpp.objbin555 -> 625 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/game/view.cpp.objbin15564 -> 16092 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/graphics/graphics.cpp.objbin226173 -> 395241 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/main.cpp.objbin302022 -> 453538 bytes
-rw-r--r--CMakeFiles/sdl_test.dir/objects.abin4076418 -> 5292794 bytes
-rw-r--r--CMakeLists.txt1
-rw-r--r--build/content/entities.json23
-rw-r--r--build/content/sprites.bmpbin3145782 -> 3145782 bytes
-rw-r--r--build/content/techs.json8
-rw-r--r--build/sdl_test.exebin2056346 -> 2389953 bytes
-rw-r--r--game/constants.h13
-rw-r--r--game/entity.h7
-rw-r--r--game/ground.cpp6
-rw-r--r--game/gst.cpp188
-rw-r--r--game/gst.h13
-rw-r--r--game/load.cpp39
-rw-r--r--game/menu.h15
-rw-r--r--game/player.h31
-rw-r--r--game/playercontrol.cpp147
-rw-r--r--game/playercontrol.h2
-rw-r--r--game/tech.h53
-rw-r--r--game/view.cpp24
-rw-r--r--game/view.h2
-rw-r--r--graphics/graphics.cpp116
-rw-r--r--main.cpp10
-rw-r--r--notes.txt30
34 files changed, 619 insertions, 531 deletions
diff --git a/CMakeFiles/sdl_test.dir/CXX.includecache b/CMakeFiles/sdl_test.dir/CXX.includecache
index cf9bd6c..c1a7a4e 100644
--- a/CMakeFiles/sdl_test.dir/CXX.includecache
+++ b/CMakeFiles/sdl_test.dir/CXX.includecache
@@ -630,12 +630,6 @@ vector
SDL2/SDL.h
-
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/entity.cpp
-entity.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/entity.h
-iostream
--
-
C:/Users/jaksk/Desktop/dev/_cpp/age/game/entity.h
vector
-
@@ -646,26 +640,10 @@ iostream
../umath/vec2.h
C:/Users/jaksk/Desktop/dev/_cpp/age/umath/vec2.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/ground.cpp
-ground.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/ground.h
-gst.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/gst.h
-iostream
--
-algorithm
--
-
C:/Users/jaksk/Desktop/dev/_cpp/age/game/ground.h
entity.h
C:/Users/jaksk/Desktop/dev/_cpp/age/game/entity.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/gst.cpp
-gst.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/gst.h
-iostream
--
-
C:/Users/jaksk/Desktop/dev/_cpp/age/game/gst.h
iostream
-
@@ -688,18 +666,6 @@ C:/Users/jaksk/Desktop/dev/_cpp/age/game/player.h
tech.h
C:/Users/jaksk/Desktop/dev/_cpp/age/game/tech.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/load.cpp
-iostream
--
-fstream
--
-vector
--
-load.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/load.h
-nlohmann/json.hpp
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/nlohmann/json.hpp
-
C:/Users/jaksk/Desktop/dev/_cpp/age/game/load.h
gst.h
C:/Users/jaksk/Desktop/dev/_cpp/age/game/gst.h
@@ -714,371 +680,11 @@ C:/Users/jaksk/Desktop/dev/_cpp/age/umath/vec2.h
tech.h
C:/Users/jaksk/Desktop/dev/_cpp/age/game/tech.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/nlohmann/json.hpp
-algorithm
--
-cstddef
--
-functional
--
-initializer_list
--
-iosfwd
--
-iterator
--
-memory
--
-numeric
--
-string
--
-utility
--
-vector
--
-type_traits
--
-utility
--
-algorithm
--
-array
--
-forward_list
--
-iterator
--
-map
--
-string
--
-tuple
--
-type_traits
--
-unordered_map
--
-utility
--
-valarray
--
-exception
--
-stdexcept
--
-string
--
-vector
--
-array
--
-cstddef
--
-cstdint
--
-string
--
-string
--
-utility
--
-stdint.h
--
-stdint.h
--
-cstdlib
--
-cassert
--
-cstddef
--
-cstddef
--
-type_traits
--
-utility
--
-limits
--
-type_traits
--
-utility
--
-tuple
--
-iterator
--
-type_traits
--
-cstdint
--
-map
--
-memory
--
-string
--
-vector
--
-algorithm
--
-iterator
--
-string
--
-tuple
--
-type_traits
--
-utility
--
-valarray
--
-vector
--
-cstddef
--
-iterator
--
-string
--
-tuple
--
-utility
--
-cstdint
--
-tuple
--
-utility
--
-cstdint
--
-cstddef
--
-functional
--
-algorithm
--
-array
--
-cmath
--
-cstddef
--
-cstdint
--
-cstdio
--
-cstring
--
-iterator
--
-limits
--
-string
--
-utility
--
-vector
--
-array
--
-cstddef
--
-cstring
--
-iterator
--
-memory
--
-numeric
--
-string
--
-type_traits
--
-utility
--
-cstdio
--
-istream
--
-cstddef
--
-string
--
-utility
--
-vector
--
-array
--
-clocale
--
-cstddef
--
-cstdio
--
-cstdlib
--
-initializer_list
--
-string
--
-utility
--
-vector
--
-cstdint
--
-utility
--
-string
--
-cmath
--
-cstdint
--
-functional
--
-string
--
-utility
--
-vector
--
-cstddef
--
-limits
--
-iterator
--
-type_traits
--
-cstddef
--
-iterator
--
-utility
--
-algorithm
--
-cctype
--
-limits
--
-numeric
--
-string
--
-utility
--
-vector
--
-initializer_list
--
-utility
--
-algorithm
--
-array
--
-cmath
--
-cstdint
--
-cstring
--
-limits
--
-string
--
-utility
--
-algorithm
--
-cstddef
--
-iterator
--
-memory
--
-string
--
-vector
--
-ios
--
-ostream
--
-algorithm
--
-array
--
-clocale
--
-cmath
--
-cstddef
--
-cstdint
--
-cstdio
--
-limits
--
-string
--
-type_traits
--
-utility
--
-array
--
-cmath
--
-cstdint
--
-cstring
--
-limits
--
-type_traits
--
-functional
--
-initializer_list
--
-iterator
--
-memory
--
-stdexcept
--
-type_traits
--
-utility
--
-vector
--
-string_view
--
-
C:/Users/jaksk/Desktop/dev/_cpp/age/game/player.h
vector
-
-
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/playercontrol.cpp
-iostream
--
-string
--
-playercontrol.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/playercontrol.h
-entity.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/entity.h
+tech.h
+C:/Users/jaksk/Desktop/dev/_cpp/age/game/tech.h
C:/Users/jaksk/Desktop/dev/_cpp/age/game/playercontrol.h
iostream
@@ -1095,6 +701,8 @@ functional
C:/Users/jaksk/Desktop/dev/_cpp/age/game/tech.h
vector
-
+unordered_map
+-
string
-
../umath/vec2.h
@@ -1108,10 +716,6 @@ string
../umath/vec2.h
C:/Users/jaksk/Desktop/dev/_cpp/age/umath/vec2.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/view.cpp
-view.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/view.h
-
C:/Users/jaksk/Desktop/dev/_cpp/age/game/view.h
vector
-
@@ -1126,22 +730,6 @@ C:/Users/jaksk/Desktop/dev/_cpp/age/graphics/cam.h
vector
-
-C:/Users/jaksk/Desktop/dev/_cpp/age/graphics/graphics.cpp
-algorithm
--
-iostream
--
-string
--
-math.h
--
-graphics.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/graphics/graphics.h
-../game/menu.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/menu.h
-../game/tile.h
-C:/Users/jaksk/Desktop/dev/_cpp/age/game/tile.h
-
C:/Users/jaksk/Desktop/dev/_cpp/age/graphics/graphics.h
vector
-
diff --git a/CMakeFiles/sdl_test.dir/depend.internal b/CMakeFiles/sdl_test.dir/depend.internal
index f191c0c..7277f69 100644
--- a/CMakeFiles/sdl_test.dir/depend.internal
+++ b/CMakeFiles/sdl_test.dir/depend.internal
@@ -166,6 +166,7 @@ CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj
C:/MinGW_libs/include/SDL2/SDL_video.h
C:/MinGW_libs/include/SDL2/begin_code.h
C:/MinGW_libs/include/SDL2/close_code.h
+ C:/Users/jaksk/Desktop/dev/_cpp/age/game/constants.h
C:/Users/jaksk/Desktop/dev/_cpp/age/game/entity.h
C:/Users/jaksk/Desktop/dev/_cpp/age/game/ground.h
C:/Users/jaksk/Desktop/dev/_cpp/age/game/gst.h
diff --git a/CMakeFiles/sdl_test.dir/depend.make b/CMakeFiles/sdl_test.dir/depend.make
index e197c59..2e68f12 100644
--- a/CMakeFiles/sdl_test.dir/depend.make
+++ b/CMakeFiles/sdl_test.dir/depend.make
@@ -165,6 +165,7 @@ CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj: C:/MinGW_libs/include/SDL2/SD
CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj: C:/MinGW_libs/include/SDL2/SDL_video.h
CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj: C:/MinGW_libs/include/SDL2/begin_code.h
CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj: C:/MinGW_libs/include/SDL2/close_code.h
+CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj: game/constants.h
CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj: game/entity.h
CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj: game/ground.h
CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj: game/gst.h
diff --git a/CMakeFiles/sdl_test.dir/game/ground.cpp.obj b/CMakeFiles/sdl_test.dir/game/ground.cpp.obj
index 2426007..e8fe88d 100644
--- a/CMakeFiles/sdl_test.dir/game/ground.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/game/ground.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/game/gst.cpp.obj b/CMakeFiles/sdl_test.dir/game/gst.cpp.obj
index 1ade445..622f3c3 100644
--- a/CMakeFiles/sdl_test.dir/game/gst.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/game/gst.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/game/load.cpp.obj b/CMakeFiles/sdl_test.dir/game/load.cpp.obj
index 5fee533..b227260 100644
--- a/CMakeFiles/sdl_test.dir/game/load.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/game/load.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/game/menu.cpp.obj b/CMakeFiles/sdl_test.dir/game/menu.cpp.obj
index 507e390..a1d1697 100644
--- a/CMakeFiles/sdl_test.dir/game/menu.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/game/menu.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/game/playercontrol.cpp.obj b/CMakeFiles/sdl_test.dir/game/playercontrol.cpp.obj
index 7b273d0..c1c6716 100644
--- a/CMakeFiles/sdl_test.dir/game/playercontrol.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/game/playercontrol.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/game/tech.cpp.obj b/CMakeFiles/sdl_test.dir/game/tech.cpp.obj
index dbf13d3..88191d8 100644
--- a/CMakeFiles/sdl_test.dir/game/tech.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/game/tech.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/game/view.cpp.obj b/CMakeFiles/sdl_test.dir/game/view.cpp.obj
index 5292e10..1495405 100644
--- a/CMakeFiles/sdl_test.dir/game/view.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/game/view.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj b/CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj
index 1823965..d3970de 100644
--- a/CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/graphics/graphics.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/main.cpp.obj b/CMakeFiles/sdl_test.dir/main.cpp.obj
index 902c25e..d873aa1 100644
--- a/CMakeFiles/sdl_test.dir/main.cpp.obj
+++ b/CMakeFiles/sdl_test.dir/main.cpp.obj
Binary files differ
diff --git a/CMakeFiles/sdl_test.dir/objects.a b/CMakeFiles/sdl_test.dir/objects.a
index f1914f9..35d3bbc 100644
--- a/CMakeFiles/sdl_test.dir/objects.a
+++ b/CMakeFiles/sdl_test.dir/objects.a
Binary files differ
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0b54e6b..6a6bab2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,7 @@ add_executable(sdl_test
game/load.cpp game/load.h
game/tech.cpp game/tech.h
game/player.h
+ game/constants.h
umath/vec2.h)
target_include_directories(sdl_test PUBLIC "C:/MinGW_libs/include")
diff --git a/build/content/entities.json b/build/content/entities.json
index 06026e6..db04571 100644
--- a/build/content/entities.json
+++ b/build/content/entities.json
@@ -48,7 +48,7 @@
"id": 105, "unit": 0, "class": "bld", "level": 1,
"move" : 0, "attack": 0, "defence": 300,
"range": 0, "sight": 7,
- "spritebounds": [ 608, 16 ],
+ "spritebounds": [ 608, 32 ],
"train": [ 5 ],
"prod": [ 0, 0 ],
"cost": [ 360, 240 ],
@@ -58,7 +58,7 @@
"id": 106, "unit": 0, "class": "bld", "level": 1,
"move" : 0, "attack": 0, "defence": 300,
"range": 0, "sight": 7,
- "spritebounds": [ 624, 16 ],
+ "spritebounds": [ 624, 32 ],
"prod": [ 0, 0 ],
"cost": [ 285, 165 ],
"adjacent": [ 100 ]
@@ -67,7 +67,7 @@
"id": 107, "unit": 0, "class": "bld", "level": 1,
"move" : 0, "attack": 0, "defence": 300,
"range": 0, "sight": 7,
- "spritebounds": [ 640, 16 ],
+ "spritebounds": [ 640, 32 ],
"prod": [ 0, 0 ],
"cost": [ 360, 240 ],
"adjacent": [ 100 ]
@@ -85,7 +85,7 @@
"id": 109, "unit": 0, "class": "bld", "level": 2,
"move" : 0, "attack": 0, "defence": 300,
"range": 0, "sight": 7,
- "spritebounds": [ 672, 16 ],
+ "spritebounds": [ 672, 48 ],
"prod": [ 0, 0 ],
"cost": [ 360, 240 ],
"adjacent": [ 100 ]
@@ -94,7 +94,7 @@
"id": 110, "unit": 0, "class": "bld", "level": 2,
"move" : 0, "attack": 0, "defence": 300,
"range": 0, "sight": 7,
- "spritebounds": [ 688, 16 ],
+ "spritebounds": [ 688, 48 ],
"prod": [ 0, 0 ],
"cost": [ 360, 240 ],
"adjacent": [ 100 ]
@@ -103,16 +103,16 @@
"id": 111, "unit": 0, "class": "bld", "level": 2,
"move" : 0, "attack": 0, "defence": 300,
"range": 0, "sight": 7,
- "spritebounds": [ 704, 16 ],
+ "spritebounds": [ 704, 48 ],
"prod": [ 0, 0 ],
"cost": [ 360, 240 ],
"adjacent": [ 100 ]
},{
"name": "Tower",
- "id": 112, "unit": 0, "class": "bld", "level": 2,
+ "id": 112, "unit": 0, "class": "bld", "level": 1,
"move" : 0, "attack": 0, "defence": 300,
"range": 0, "sight": 7,
- "spritebounds": [ 720, 16 ],
+ "spritebounds": [ 720, 48 ],
"prod": [ 0, 0 ],
"cost": [ 360, 240 ],
"diagonal": [ 100 ]
@@ -121,18 +121,19 @@
"id": 113, "unit": 0, "class": "bld", "level": 2,
"move" : 0, "attack": 0, "defence": 300,
"range": 0, "sight": 7,
- "spritebounds": [ 720, 16 ],
+ "spritebounds": [ 720, 48 ],
"prod": [ 0, 0 ],
"cost": [ 360, 240 ],
"diagonal": [ 100 ]
},{
"name": "Villager",
- "id": 0, "unit": 1, "class": "inf", "level": -1,
+ "id": 0, "unit": 1, "class": "inf", "level": -1,
"move" : 7, "attack": 50, "defence": 50,
"range": 1, "sight": 7,
"spritebounds": [ 96, 16 ],
"build": [
- 100, 101, 102, 103, 104, 105, 106, 107
+ 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
+ 111, 112, 113
],
"cost": [ 100, 100 ]
},{
diff --git a/build/content/sprites.bmp b/build/content/sprites.bmp
index 0cb4039..4a70921 100644
--- a/build/content/sprites.bmp
+++ b/build/content/sprites.bmp
Binary files differ
diff --git a/build/content/techs.json b/build/content/techs.json
index df2ac8d..3476177 100644
--- a/build/content/techs.json
+++ b/build/content/techs.json
@@ -52,6 +52,7 @@
"name": "Horse Collar", "id": 7, "level": 1,
"cost": [ 95, 280 ], "req_id": 101,
"bonus": {
+ "aff_all": 1,
"prod": [ 0.15, 0 ]
}
},{
@@ -105,18 +106,21 @@
"name": "Cartography", "id": 14, "level": 1,
"cost": [ 95, 280 ], "req_id": 107,
"bonus": {
+ "aff_all": 1,
"sight": 1
}
},{
"name": "Trading", "id": 15, "level": 1,
"cost": [ 95, 280 ], "req_id": 107,
"bonus": {
+ "aff_all": 1,
"trade": 1
}
},{
"name": "Coniage", "id": 16, "level": 1,
"cost": [ 125, 375 ], "req_id": 107,
"bonus": {
+ "aff_all": 1,
"prod": [ 0, 0.1 ]
}
},{
@@ -144,6 +148,7 @@
"name": "Heavy Plow", "id": 20, "level": 2,
"cost": [ 150, 450 ], "req_id": 101,
"bonus": {
+ "aff_all": 1,
"prod": [ 0.1, 0 ]
}
},{
@@ -218,6 +223,7 @@
"name": "Banking", "id": 30, "level": 2,
"cost": [ 200, 600 ], "req_id": 107,
"bonus": {
+ "aff_all": 1,
"trade": 1,
"prod": [ 0, 0.05 ]
}
@@ -267,6 +273,7 @@
"name": "Crop Rotation", "id": 37, "level": 3,
"cost": [ 250, 750 ], "req_id": 101,
"bonus": {
+ "aff_all": 1,
"prod": [ 0.1, 0 ]
}
},{
@@ -335,6 +342,7 @@
"name": "Guilds", "id": 49, "level": 3,
"cost": [ 250, 750 ], "req_id": 107,
"bonus": {
+ "aff_all": 1,
"trade": 1,
"prod": [ 0, 0.05 ]
}
diff --git a/build/sdl_test.exe b/build/sdl_test.exe
index 12fa827..752ac84 100644
--- a/build/sdl_test.exe
+++ b/build/sdl_test.exe
Binary files differ
diff --git a/game/constants.h b/game/constants.h
new file mode 100644
index 0000000..7ea34e0
--- /dev/null
+++ b/game/constants.h
@@ -0,0 +1,13 @@
+#ifndef CONSTANTS_H
+#define CONSTANTS_H
+
+namespace constants {
+ const int col_gud_r = 40;
+ const int col_gud_g = 120;
+ const int col_gud_b = 0;
+ const int col_bad_r = 255;
+ const int col_bad_g = 120;
+ const int col_bad_b = 0;
+}
+
+#endif \ No newline at end of file
diff --git a/game/entity.h b/game/entity.h
index eeab110..50c7acc 100644
--- a/game/entity.h
+++ b/game/entity.h
@@ -16,6 +16,7 @@ class EntityInfo {
std::string name;
int id;
+ int level;
float hp;
float attack;
@@ -28,11 +29,13 @@ class EntityInfo {
std::vector<int> build;
std::vector<int> train;
- std::vector<int> prod { 0, 0 };
- std::vector<int> cost { 0, 0 };
+ std::vector<float> prod { 0, 0 };
+ std::vector<float> cost { 0, 0 };
std::vector<int> adjacent;
+ int upgrade { -1 };
+
enum Class { inf, cav, ran, sie, bld };
Class ent_class;
diff --git a/game/ground.cpp b/game/ground.cpp
index e6055bf..4308047 100644
--- a/game/ground.cpp
+++ b/game/ground.cpp
@@ -38,9 +38,13 @@ class step { public:
};
std::vector<int> Ground::move_area (Gst &gst, Entity &ent) {
+ Player &player = gst.players[ent.owner];
+ int move_num = ent.info->move;
+ move_num += player.tech_lookup.id(ent.info->id).move;
+
std::vector<int> moves;
std::vector<int> visited { at(ent.x, ent.y) };
- std::vector<step> frontier { step { at(ent.x, ent.y), ent.info->move } };
+ std::vector<step> frontier { step { at(ent.x, ent.y), move_num } };
int maxcost = 99;
if (gst.info_has_ability(ent.info, "Scout")) maxcost = 2;
diff --git a/game/gst.cpp b/game/gst.cpp
index 0a524fc..5c7485b 100644
--- a/game/gst.cpp
+++ b/game/gst.cpp
@@ -1,7 +1,20 @@
#include "gst.h"
+#include <map>
#include <iostream>
+Player& Gst::get_player (int id) {
+ for (auto &player : players) {
+ if (id == player.id) return player;
+ }
+}
+
+Tech* Gst::get_tech (int id) {
+ for (auto &tech : techs) {
+ if (id == tech.id) return &tech;
+ }
+}
+
EntityInfo* Gst::get_info (std::string name) {
for (EntityInfo &info : infos) {
if (name == info.name) return &info;
@@ -27,6 +40,21 @@ Entity& Gst::get_at (int x, int y) {
}
}
+std::vector<float> Gst::get_cost (EntityInfo *info, Player &player) {
+ std::vector<float> cost = info->cost;
+ for (int i=0; i<info->cost.size(); i++) {
+ cost[i] *= 1+player.tech_lookup.id(info->id).cost[i];
+ cost[i] += player.tech_lookup.id(info->id).cost_abs[i];
+ }
+ return cost;
+}
+
+float Gst::get_trade_rate (Player &player) {
+ float rate = 250;
+ rate -= player.tech_lookup.id(0).trade * 25;
+ return rate;
+}
+
float Gst::get_type_bonus (Entity &atk, Entity &def) {
float b = 0;
switch(atk.info->ent_class) {
@@ -104,6 +132,16 @@ std::vector<Bonus> Gst::get_bonuses (Entity &atk, Entity &def) {
if (info_has_ability(atk.info, "Frenzy"))
bs.emplace_back(1/atk.hp, Bonus::Id::ability, true);
+
+ Player &player_atk = players[atk.owner];
+ Player &player_def = players[def.owner];
+ float tech_attack = player_atk.tech_lookup.id(atk.info->id).attack;
+ if (tech_attack != 0)
+ bs.emplace_back(tech_attack, Bonus::Id::tech, true);
+ float tech_defence = player_def.tech_lookup.id(def.info->id).defence;
+ if (tech_defence != 0)
+ bs.emplace_back(tech_defence, Bonus::Id::tech, false);
+
return bs;
}
@@ -133,7 +171,7 @@ bool Gst::get_first_strike (Entity &atk, Entity &def) {
return fs;
}
-float clamp (float hp) {
+float clamp_hp (float hp) {
if (hp > 100) hp = 100;
if (hp < 0) hp = 0;
return hp;
@@ -163,36 +201,36 @@ BattleResult Gst::battle_res (Entity &atk, Entity &def) {
if (first_strike_def && !first_strike_atk) swap = true;
if (swap) {
if (def_inrange) {
- result.atk_hp = clamp(
+ result.atk_hp = clamp_hp(
result.atk_hp - get_damage(def, atk, result.def_hp));
}
if (!info_has_ability(atk.info, "No Counter"))
if (result.atk_hp > 0)
- result.def_hp = clamp(
+ result.def_hp = clamp_hp(
result.def_hp - get_damage(atk, def, result.atk_hp));
} else {
- result.def_hp = clamp(
+ result.def_hp = clamp_hp(
result.def_hp - get_damage(atk, def, result.atk_hp));
if (!info_has_ability(def.info, "No Counter") && def_inrange)
if (result.def_hp > 0)
- result.atk_hp = clamp(
+ result.atk_hp = clamp_hp(
result.atk_hp - get_damage(def, atk, result.def_hp));
}
if (info_has_ability(atk.info, "Rapid Fire"))
if (result.def_hp > 0)
- result.def_hp = clamp(
+ result.def_hp = clamp_hp(
result.def_hp - get_damage(atk, def, result.def_hp));
if (info_has_ability(def.info, "Rapid Fire") && def_inrange)
if (result.atk_hp > 0)
- result.atk_hp = clamp(
+ result.atk_hp = clamp_hp(
result.atk_hp - get_damage(def, atk, result.def_hp));
if (result.atk_hp > 0 && info_has_ability(atk.info, "Zeal"))
- result.atk_hp = clamp(result.atk_hp + 20);
+ result.atk_hp = clamp_hp(result.atk_hp + 20);
if (result.def_hp > 0 && info_has_ability(def.info, "Zeal"))
- result.def_hp = clamp(result.def_hp + 20);
+ result.def_hp = clamp_hp(result.def_hp + 20);
return result;
}
@@ -239,7 +277,10 @@ std::vector<int> Gst::get_possible_builds (Entity &ent) {
return builds;
}
+
bool Gst::check_req_build(Entity &ent, EntityInfo *info) {
+ Player &player = players[ent.owner];
+ if (player.level < info->level) return false;
for (int id : info->adjacent) {
bool adj = false;
for (Entity &e : entities) {
@@ -294,6 +335,63 @@ bool Gst::check_req_build(Entity &ent, EntityInfo *info) {
return true;
}
+bool Gst::check_req_train (Entity &ent, EntityInfo *info) {
+ Player &player = players[ent.owner];
+ if (player.level < info->level) return false;
+ return true;
+}
+
+
+bool Gst::check_req_tech (Tech *tech, Player &player) {
+ if (player.leveling_up == 1) return false;
+ if (tech->level > player.level) {
+ return false;
+ }
+ if (tech->cost[0] > player.res[0]
+ || tech->cost[1] > player.res[1] )
+ {
+ return false;
+ }
+ if (player.has_tech(tech->id)) {
+ return false;
+ }
+ bool req_id = false;
+ for (auto &ent : entities) {
+ if (ent.owner == turn // WARNING: turn is not player.id
+ && ent.info->id == tech->req_id
+ && ent.building == 0)
+ {
+ req_id = true;
+ break;
+ }
+ }
+ if (!req_id) {
+ return false;
+ }
+ return true;
+}
+
+bool Gst::check_req_level (Player &player) {
+ if (player.leveling_up == 1) return false;
+
+ for (float v : player.res) {
+ if (v <= (player.level+1)*500) return false;
+ }
+
+ std::map<int, int> lv_techs;
+ for (int id : player.techs) lv_techs[get_tech(id)->level] ++;
+ if (player.level == 0) {
+ if (lv_techs[0] >= 3) return true;
+ }
+ if (player.level == 1) {
+ if (lv_techs[1] >= 7) return true;
+ }
+ if (player.level == 2) {
+ if (lv_techs[2] >= 11) return true;
+ }
+ return false;
+}
+
bool Gst::check_obstructed (Entity &ent) {
for (Entity &e : entities) {
if (&ent != &e && e.x == ent.x && ent.y == e.y) return true;
@@ -307,21 +405,83 @@ void Gst::end_day () {
turn = 0;
day++;
}
+ Player &player = players[turn];
+ if (player.leveling_up != -1) {
+ level_upgrade(player);
+ player.level ++;
+ player.leveling_up = -1;
+ }
for (Entity &e : entities) {
e.done = false;
e.moved = 0;
- if (e.owner == turn) {
- Player &player = players[e.owner];
+ if (get_player(e.owner) == player) {
for (int i=0; i<player.res.size(); i++) {
- player.res[i] += e.info->prod[i];
+ player.res[i] += e.info->prod[i] *
+ (1+player.tech_lookup.id(e.info->id).prod[i]);
}
- // todo heal when on top of building
if (e.building < 0) {
e.building++;
if (e.building == 0) {
- e.hp += 50; if (e.hp > 100) e.hp = 100;
+ e.hp = clamp_hp(e.hp + 50);
+ }
+ }
+ if (e.info->unit == 1 && check_obstructed(e)) {
+ e.hp = clamp_hp(e.hp + 20);
+ }
+ }
+ }
+ if (player.researching != -1) {
+ player.techs.push_back(player.researching);
+ update_tech_lookup(player);
+ player.researching = -1;
+ }
+}
+
+void Gst::level_upgrade (Player &player) {
+ for (Entity &e : entities) {
+ if (get_player(e.owner) == player) {
+ if (e.info->upgrade != -1 && e.info->level == player.level) {
+ e.info = get_info(e.info->upgrade);
+ }
+ }
+ }
+}
+
+
+void Gst::update_tech_lookup (Player &player) {
+ player.tech_lookup.map_id.clear();
+ for (int i : player.techs) {
+ Tech *tech = get_tech(i);
+ std::vector<int> ids { };
+ if (tech->bonus.aff_id.size() > 0) {
+ ids = tech->bonus.aff_id;
+ } else {
+ if (tech->bonus.aff_level != -1) {
+ for (EntityInfo info : infos) {
+ if (info.level == tech->bonus.aff_level) {
+ ids.push_back(info.id);
+ }
+ }
+ }
+ if (tech->bonus.aff_class.size() > 0) {
+ for (EntityInfo info : infos) {
+ auto &cls = tech->bonus.aff_class;
+ if (std::find(cls.begin(), cls.end(),
+ info.ent_class) != cls.end())
+ {
+ ids.push_back(info.id);
+ }
}
}
+ if (tech->bonus.aff_all == 1) {
+ for (EntityInfo info : infos) {
+ ids.push_back(info.id);
+ }
+ }
+ }
+ for (int id : ids) {
+ player.tech_lookup.map_id[id] =
+ player.tech_lookup.map_id[id] + tech->bonus;
}
}
} \ No newline at end of file
diff --git a/game/gst.h b/game/gst.h
index 906b372..c9c5d3c 100644
--- a/game/gst.h
+++ b/game/gst.h
@@ -54,10 +54,14 @@ class Gst {
std::vector<Player> players;
+ Player& get_player (int id);
+ Tech* get_tech (int id);
EntityInfo* get_info (std::string name);
EntityInfo* get_info (int id);
bool info_has_ability (EntityInfo* info, std::string name);
Entity& get_at (int x, int y);
+ std::vector<float> get_cost (EntityInfo *info, Player &player);
+ float get_trade_rate (Player &player);
float get_type_bonus (Entity &atk, Entity &def);
std::vector<Bonus> get_bonuses (Entity &atk, Entity &def);
@@ -71,14 +75,19 @@ class Gst {
std::vector<int> get_possible_builds (Entity &ent);
- bool check_req_build(Entity &ent, EntityInfo *info);
-
+ bool check_req_build (Entity &ent, EntityInfo *info);
+ bool check_req_train (Entity &ent, EntityInfo *info);
+ bool check_req_tech (Tech *tech, Player &player);
+ bool check_req_level (Player &player);
bool check_obstructed (Entity &ent);
int turn { 0 };
int day { 0 };
void end_day ();
+ void level_upgrade (Player &player);
+
+ void update_tech_lookup (Player &player);
};
#endif \ No newline at end of file
diff --git a/game/load.cpp b/game/load.cpp
index 5baae6c..c9c9132 100644
--- a/game/load.cpp
+++ b/game/load.cpp
@@ -53,6 +53,7 @@ void load_json (Gst &gst) {
EntityInfo ent;
ent.id = it["id"];
ent.name = it["name"];
+ ent.level = it["level"];
ent.range = it["range"];
ent.move = it["move"];
ent.attack = it["attack"];
@@ -88,6 +89,7 @@ void load_json (Gst &gst) {
ent.abilities.push_back(index);
}
ent.spritebounds = vec2 { it["spritebounds"][0], it["spritebounds"][1] };
+ if (it.contains("upgrade")) { ent.upgrade = it["upgrade"]; }
gst.infos.push_back(ent);
}
@@ -102,6 +104,43 @@ void load_json (Gst &gst) {
for (int i=0; i<it["cost"].size(); i++) {
tech.cost[i] = it["cost"][i];
}
+ auto b = it["bonus"];
+ if (b != nullptr) {
+ if (b.contains("attack")) { tech.bonus.attack = b["attack"]; }
+ if (b.contains("defence")) { tech.bonus.defence = b["defence"]; }
+ if (b.contains("sight")) { tech.bonus.sight = b["sight"]; }
+ if (b.contains("move")) { tech.bonus.move = b["move"]; }
+ if (b.contains("trade")) { tech.bonus.trade = b["trade"]; }
+ if (b.contains("req_range")) {
+ tech.bonus.req_range = b["req_range"];
+ }
+ if (b.contains("improved_heal")) {
+ tech.bonus.attack = b["improved_heal"];
+ }
+ if (b.contains("improved_convert")) {
+ tech.bonus.attack = b["improved_convert"];
+ }
+ for (auto v : b["cost"]) { tech.bonus.cost.push_back(v); }
+ for (auto v : b["cost_abs"]) { tech.bonus.cost_abs.push_back(v); }
+ for (auto v : b["prod"]) { tech.bonus.prod.push_back(v); }
+
+ for (auto v : b["aff_id"]) { tech.bonus.aff_id.push_back(v); }
+ for (auto v : b["aff_class"]) {
+ int w = -1;
+ if (v == "inf") w = EntityInfo::Class::inf;
+ if (v == "cav") w = EntityInfo::Class::cav;
+ if (v == "ran") w = EntityInfo::Class::ran;
+ if (v == "sie") w = EntityInfo::Class::sie;
+ if (v == "bld") w = EntityInfo::Class::bld;
+ tech.bonus.aff_class.push_back(w);
+ }
+ if (b.contains("aff_level")) {
+ tech.bonus.aff_level = b["aff_level"];
+ }
+ if (b.contains("aff_all")) {
+ tech.bonus.aff_all = b["aff_all"];
+ }
+ }
gst.techs.push_back(tech);
}
} \ No newline at end of file
diff --git a/game/menu.h b/game/menu.h
index 462d893..3da0c46 100644
--- a/game/menu.h
+++ b/game/menu.h
@@ -14,7 +14,7 @@ class Option {
std::string name;
int id;
- std::vector<int> cost;
+ std::vector<float> cost;
};
@@ -56,7 +56,18 @@ class Menu_train : public Menu {
public:
Menu_train () {}
};
-
+class Menu_trade : public Menu {
+ public:
+ Menu_trade () {}
+
+ enum Opts {
+ food, gold
+ };
+};
+class Menu_age_up : public Menu {
+ public:
+ Menu_age_up () {}
+};
class OptionTech {
public:
diff --git a/game/player.h b/game/player.h
index 01d8ee9..cf4146f 100644
--- a/game/player.h
+++ b/game/player.h
@@ -3,14 +3,41 @@
#include <vector>
+#include "tech.h"
+
class Player {
public:
- Player (int r, int g, int b) : r(r), g(g), b(b) { }
+ Player (int r, int g, int b, int id) : r(r), g(g), b(b), id(id) { }
+
+ void pay (std::vector<float> cost) {
+ for (int i=0; i<res.size(); i++) {
+ res[i] -= cost[i];
+ }
+ }
+ void gain (std::vector<float> gain) {
+ for (int i=0; i<res.size(); i++) {
+ res[i] += gain[i];
+ }
+ }
+
+ bool has_tech (int id) {
+ if (std::find(techs.begin(), techs.end(), id) != techs.end())
+ return true;
+ return false;
+ }
- std::vector<int> res { 0, 0 };
+ bool operator== (Player &oth) { return id == oth.id; }
+
+ int id;
+
+ std::vector<float> res { 0, 0 };
std::vector<int> techs;
+ TechLookup tech_lookup;
+
+ int researching { -1 };
+ int leveling_up { -1 };
int level { 0 };
int r, g, b;
diff --git a/game/playercontrol.cpp b/game/playercontrol.cpp
index 90e063e..284c6ff 100644
--- a/game/playercontrol.cpp
+++ b/game/playercontrol.cpp
@@ -6,37 +6,48 @@
void open_unit_menu (Gst &gst, View &view, Fsm &fsm, int p) {
Entity &ent = gst.entities[view.selected_entity];
+ Player &player = gst.players[ent.owner];
view.menu_unit.options.clear();
if (ent.info->unit == 1) {
if (gst.ground.move_area(gst, ent).size() > 0
&& ent.moved == 0)
{
- view.menu_unit.options.emplace_back("Move", Menu_unit::Opts::move);
+ view.menu_unit.options.emplace_back("Move",
+ Menu_unit::Opts::move);
}
if (gst.ground.attack_targets(gst, ent).size() > 0
&& (!gst.info_has_ability(ent.info, "No Move & Attack")
|| ent.moved == 0)) {
- view.menu_unit.options.emplace_back("Attack", Menu_unit::Opts::attack);
+ view.menu_unit.options.emplace_back("Attack",
+ Menu_unit::Opts::attack);
}
if (ent.info->build.size() > 0
&& !gst.check_obstructed(ent)
&& gst.get_possible_builds(ent).size() > 0)
{
- view.menu_unit.options.emplace_back("Build", Menu_unit::Opts::build);
+ view.menu_unit.options.emplace_back("Build",
+ Menu_unit::Opts::build);
}
- view.menu_unit.options.emplace_back("Done", Menu_unit::Opts::done);
+ view.menu_unit.options.emplace_back("Done",
+ Menu_unit::Opts::done);
} else {
if (ent.info->train.size()
&& !gst.check_obstructed(ent))
{
- view.menu_unit.options.emplace_back("Train", Menu_unit::Opts::train);
+ view.menu_unit.options.emplace_back("Train",
+ Menu_unit::Opts::train);
}
if (ent.info->id == 100
|| ent.info->id == 101) {
- view.menu_unit.options.emplace_back("Trade", Menu_unit::Opts::trade);
+ int rate = (int)gst.get_trade_rate(player);
+ if (player.res[0] >= rate || player.res[1] >= rate) {
+ view.menu_unit.options.emplace_back("Trade",
+ Menu_unit::Opts::trade);
+ }
}
if (ent.info->id == 100) {
- view.menu_unit.options.emplace_back("Age Up", Menu_unit::Opts::age_up);
+ view.menu_unit.options.emplace_back("Age Up",
+ Menu_unit::Opts::age_up);
}
}
view.menu_unit.open(view.res);
@@ -49,10 +60,14 @@ Player_control::Player_control () {
view.selected_ground = p;
std::cout << "selected ground " << p << "\n";
view.menu_day.options.clear();
- view.menu_day.options.emplace_back("End Day", Menu_day::Opts::end_day);
- view.menu_day.options.emplace_back("Research", Menu_day::Opts::tech);
- view.menu_day.options.emplace_back("Empire Review", Menu_day::Opts::empire_review);
- view.menu_day.options.emplace_back("Scoring", Menu_day::Opts::scoring);
+ view.menu_day.options.emplace_back("End Day",
+ Menu_day::Opts::end_day);
+ view.menu_day.options.emplace_back("Research",
+ Menu_day::Opts::tech);
+ view.menu_day.options.emplace_back("Empire Review",
+ Menu_day::Opts::empire_review);
+ view.menu_day.options.emplace_back("Scoring",
+ Menu_day::Opts::scoring);
view.menu_day.open(view.res);
return menu_day;
}
@@ -91,6 +106,18 @@ Player_control::Player_control () {
fsm.arcs.emplace_back(
menu_tech, opt, -1,
[](Gst &gst, View &view, Fsm &fsm, int p) {
+ if (p == -1)
+ return menu_tech;
+ Player &player = gst.players[gst.turn];
+ Tech *tech = gst.get_tech(p);
+ if (!gst.check_req_tech(tech, player)) {
+ return menu_tech;
+ }
+ if (player.researching != -1) {
+ player.gain(tech->cost);
+ }
+ player.researching = p;
+ player.pay(tech->cost);
view.menu_tech.close();
view.selected_ground = -1;
std::cout << "selected tech " << p << "\n";
@@ -128,13 +155,16 @@ Player_control::Player_control () {
view.menu_unit.close();
std::cout << "train " << p << "\n";
Entity &ent = gst.entities[view.selected_entity];
+ Player &player = gst.players[ent.owner];
view.menu_train.options.clear();
for (int id : ent.info->train) {
- std::cout << id << " " << gst.get_info(id)->name << "\n";
EntityInfo *info = gst.get_info(id);
- Option opt { info->name, id };
- opt.cost = info->cost;
- view.menu_train.options.push_back(opt);
+ if (gst.check_req_train(ent, info)) {
+ std::cout << id << " " << gst.get_info(id)->name << "\n";
+ Option opt { info->name, id };
+ opt.cost = gst.get_cost(info, player);
+ view.menu_train.options.push_back(opt);
+ }
}
view.menu_train.open(view.res);
return menu_train;
@@ -152,9 +182,7 @@ Player_control::Player_control () {
entb.hp = 50;
gst.entities.push_back(entb);
Player &player = gst.players[gst.turn];
- for (int i=0; i<player.res.size(); i++) {
- player.res[i] -= entb.info->cost[i];
- }
+ player.pay(gst.get_cost(entb.info, player));
view.selected_entity = -1;
return select;
}
@@ -165,13 +193,14 @@ Player_control::Player_control () {
view.menu_unit.close();
std::cout << "build " << p << "\n";
Entity &ent = gst.entities[view.selected_entity];
+ Player &player = gst.players[ent.owner];
view.menu_build.options.clear();
for (int id : ent.info->build) {
EntityInfo *info = gst.get_info(id);
if(!gst.check_req_build(ent, info)) continue;
std::cout << id << " " << gst.get_info(id)->name << "\n";
Option opt { info->name, id };
- opt.cost = info->cost;
+ opt.cost = gst.get_cost(info, player);
view.menu_build.options.push_back(opt);
}
view.menu_build.open(view.res);
@@ -191,9 +220,7 @@ Player_control::Player_control () {
entb.hp = 50;
gst.entities.push_back(entb);
Player &player = gst.players[gst.turn];
- for (int i=0; i<player.res.size(); i++) {
- player.res[i] -= entb.info->cost[i];
- }
+ player.pay(gst.get_cost(entb.info, player));
view.selected_entity = -1;
return select;
}
@@ -248,6 +275,82 @@ Player_control::Player_control () {
}
);
fsm.arcs.emplace_back(
+ menu_unit, opt, Menu_unit::Opts::trade,
+ [](Gst &gst, View &view, Fsm &fsm, int p) {
+ Player &player = gst.players[gst.turn];
+ view.menu_unit.close();
+ view.menu_trade.options.clear();
+ int rate = (int)gst.get_trade_rate(player);
+ if (player.res[0] >= rate) {
+ view.menu_trade.options.emplace_back(
+ std::to_string(rate) + " Food for 100 Gold",
+ Menu_trade::Opts::food);
+ }
+ if (player.res[1] >= rate) {
+ view.menu_trade.options.emplace_back(
+ std::to_string(rate) + " Gold for 100 Food",
+ Menu_trade::Opts::gold);
+ }
+ view.menu_trade.open(view.res);
+ std::cout << "trade open " << p << "\n";
+ return menu_trade;
+ }
+ );
+ fsm.arcs.emplace_back(
+ menu_trade, opt, -1,
+ [](Gst &gst, View &view, Fsm &fsm, int p) {
+ Player &player = gst.players[gst.turn];
+ view.menu_trade.close();
+ int rate = (int)gst.get_trade_rate(player);
+ int sel = p;
+ player.pay(std::vector<float>
+ { (float)rate*(1-sel), (float)rate*sel });
+ player.gain(std::vector<float>
+ { 100.0f*sel, 100.0f*(1-sel) });
+ gst.entities[view.selected_entity].done = true;
+ view.selected_entity = -1;
+ std::cout << "done trading " << p << "\n";
+ return select;
+ }
+ );
+ fsm.arcs.emplace_back(
+ menu_unit, opt, Menu_unit::Opts::age_up,
+ [](Gst &gst, View &view, Fsm &fsm, int p) {
+ Player &player = gst.players[gst.turn];
+ view.menu_unit.close();
+ view.menu_age_up.options.clear();
+ if (gst.check_req_level(player)) {
+ view.menu_age_up.options.emplace_back("Age Up", 0);
+ }
+ view.menu_age_up.open(view.res);
+ std::cout << "age up open " << p << "\n";
+ return menu_age_up;
+ }
+ );
+ fsm.arcs.emplace_back(
+ menu_age_up, opt, 0,
+ [](Gst &gst, View &view, Fsm &fsm, int p) {
+ Player &player = gst.players[gst.turn];
+ player.leveling_up = 1;
+ float cost = (player.level+1)*500;
+ player.pay(std::vector<float>{ cost, cost });
+ view.menu_age_up.close();
+ gst.entities[view.selected_entity].done = true;
+ view.selected_entity = -1;
+ std::cout << "aged up " << p << "\n";
+ return select;
+ }
+ );
+ fsm.arcs.emplace_back(
+ menu_age_up, back, -1,
+ [](Gst &gst, View &view, Fsm &fsm, int p) {
+ view.menu_age_up.close();
+ view.selected_entity = -1;
+ std::cout << "closed ageup " << p << "\n";
+ return select;
+ }
+ );
+ fsm.arcs.emplace_back(
menu_unit, opt, Menu_unit::Opts::done,
[](Gst &gst, View &view, Fsm &fsm, int p) {
view.menu_unit.close();
diff --git a/game/playercontrol.h b/game/playercontrol.h
index 3096ada..6d12026 100644
--- a/game/playercontrol.h
+++ b/game/playercontrol.h
@@ -32,6 +32,8 @@ enum pc_state {
menu_unit,
menu_day,
menu_tech,
+ menu_trade,
+ menu_age_up,
end
};
diff --git a/game/tech.h b/game/tech.h
index 84ef05c..cb5e769 100644
--- a/game/tech.h
+++ b/game/tech.h
@@ -2,10 +2,59 @@
#define TECH_H
#include <vector>
+#include <unordered_map>
#include <string>
#include "../umath/vec2.h"
+class TechBonus {
+ public:
+ float attack { 0 };
+ float defence { 0 };
+ int sight { 0 };
+ int range { 0 };
+ int move { 0 };
+ std::vector<float> cost { 0, 0 };
+ std::vector<float> cost_abs { 0, 0 };
+ std::vector<float> prod { 0, 0 };
+ int trade;
+ int improved_heal;
+ int improved_convert;
+ int req_range { 999 };
+
+ std::vector<int> aff_id;
+ std::vector<int> aff_class;
+ int aff_level;
+ int aff_all { 0 };
+
+ TechBonus operator+(const TechBonus &rhs) {
+ TechBonus b;
+ b.attack = attack + rhs.attack;
+ b.defence = defence + rhs.defence;
+ b.sight = sight + rhs.sight;
+ b.move = move + rhs.move;
+ for (int i=0; i<b.cost.size(); i++) {
+ b.cost[i] = cost[i] + rhs.cost[i];
+ b.cost_abs[i] = cost_abs[i] + rhs.cost_abs[i];
+ b.prod[i] = prod[i] + rhs.prod[i];
+ }
+ b.trade = trade + rhs.trade;
+ b.improved_heal = improved_heal + rhs.improved_heal;
+ b.improved_convert = improved_convert + rhs.improved_convert;
+ return b;
+ }
+
+};
+
+class TechLookup {
+ public:
+ TechLookup() {}
+
+ TechBonus id (int i) { return map_id[i]; }
+
+ std::unordered_map<int, TechBonus> map_id;
+};
+
class Tech {
public:
Tech() {}
@@ -14,7 +63,9 @@ class Tech {
int id;
int level;
int req_id;
- std::vector<int> cost { 0, 0 };
+ std::vector<float> cost { 0, 0 };
+
+ TechBonus bonus;
vec2 spritebounds { 0, 0 };
};
diff --git a/game/view.cpp b/game/view.cpp
index 095a99a..7fddcd5 100644
--- a/game/view.cpp
+++ b/game/view.cpp
@@ -41,6 +41,12 @@ void View::process (Gst &gst, vec2 cam, vec2 mouse, int *mheld) {
if (menu_tech.active) {
menu_tech.over = menu_tech.mouse_option(mouse);
}
+ if (menu_trade.active) {
+ menu_trade.over = menu_trade.mouse_option(mouse);
+ }
+ if (menu_age_up.active) {
+ menu_age_up.over = menu_age_up.mouse_option(mouse);
+ }
if (mheld[0] == 1) {
bool found = false;
@@ -124,6 +130,24 @@ void View::process (Gst &gst, vec2 cam, vec2 mouse, int *mheld) {
back = 1; found = 1;
}
}
+
+ if (menu_trade.active && !found) {
+ int selected = menu_trade.mouse_option(mouse);
+ if (selected != -1) {
+ opt = selected; found = true;
+ } else {
+ back = 1; found = 1;
+ }
+ }
+
+ if (menu_age_up.active && !found) {
+ int selected = menu_age_up.mouse_option(mouse);
+ if (selected != -1) {
+ opt = selected; found = true;
+ } else {
+ back = 1; found = 1;
+ }
+ }
for (int i=0; i<entities.size() && !found; i++) {
if (entities[i].done) continue;
diff --git a/game/view.h b/game/view.h
index 5aab193..61301ac 100644
--- a/game/view.h
+++ b/game/view.h
@@ -29,6 +29,8 @@ class View {
Menu_build menu_build;
Menu_train menu_train;
Menu_tech menu_tech;
+ Menu_trade menu_trade;
+ Menu_age_up menu_age_up;
void process (Gst &gst, vec2 cam, vec2 mouse, int *mheld);
};
diff --git a/graphics/graphics.cpp b/graphics/graphics.cpp
index 3b943a4..71ff3b8 100644
--- a/graphics/graphics.cpp
+++ b/graphics/graphics.cpp
@@ -7,6 +7,7 @@
#include "graphics.h"
#include "../game/menu.h"
#include "../game/tile.h"
+#include "../game/constants.h"
Graphics::~Graphics () {
}
@@ -15,29 +16,39 @@ void Graphics::present () {
backend.present();
}
+void render_ent (Graphics *graphics, Gst &gst, Entity &ent,
+ vec2 pos, int dflag)
+{
+ Player &player = gst.players[ent.owner];
+ int done = 0;
+ if (dflag == 1) done = 512;
+ graphics->backend.render_sprite(
+ (int)ent.info->spritebounds.x,
+ (int)ent.info->spritebounds.y+done, 16, 16,
+ (int)pos.x, (int)pos.y, 32, 32
+ );
+ if (dflag == 0) {
+ graphics->backend.render_sprite(
+ (int)ent.info->spritebounds.x,
+ (int)ent.info->spritebounds.y+768, 16, 16,
+ (int)pos.x, (int)pos.y, 32, 32,
+ player.r, player.g, player.b
+ );
+ }
+}
+
void render_ents (Graphics *graphics, Gst &gst, int unit) {
std::vector<Entity> &entities = gst.entities;
for (int i=0; i<entities.size(); i++) {
if (entities[i].info->unit != unit) continue;
- int done = 0;
- if (unit == 1) done += 512 * entities[i].done;
-
Player &player = gst.players[entities[i].owner];
- graphics->backend.render_sprite(
- (int)entities[i].info->spritebounds.x,
- (int)entities[i].info->spritebounds.y+done, 16, 16,
- (int)graphics->cam.pos.x + (int)entities[i].x*32,
- (int)graphics->cam.pos.y + (int)entities[i].y*32, 32, 32
- );
- if (done == 0) {
- graphics->backend.render_sprite(
- (int)entities[i].info->spritebounds.x,
- (int)entities[i].info->spritebounds.y+768, 16, 16,
- (int)graphics->cam.pos.x + (int)entities[i].x*32,
- (int)graphics->cam.pos.y + (int)entities[i].y*32, 32, 32,
- player.r, player.g, player.b
- );
- }
+ int dflag = 0;
+ if (unit) dflag = entities[i].done;
+ vec2 pos {
+ graphics->cam.pos.x + entities[i].x*32,
+ graphics->cam.pos.y + entities[i].y*32
+ };
+ render_ent(graphics, gst, entities[i], pos, dflag);
}
}
@@ -65,10 +76,10 @@ void render_menu (Graphics *graphics, Gst &gst, Menu &menu) {
float width = graphics->backend.txt.get_width(opt.name);
if (opt.cost.size() > 0) {
graphics->backend.txt.render_text(
- std::to_string (opt.cost[0]) + "f",
+ std::to_string((int)roundf(opt.cost[0])) + "f",
menu.pos + vec2 { width + 20, 10 + acc });
graphics->backend.txt.render_text(
- std::to_string (opt.cost[1]) + "g",
+ std::to_string((int)roundf(opt.cost[1])) + "g",
menu.pos + vec2 { width + 50, 10 + acc });
}
acc += 20;
@@ -98,25 +109,13 @@ void render_menu_tech (Graphics *graphics, Gst &gst, View &view) {
if (opt.tech->id == view.menu_tech.over) {
r = player.r; g = player.g; b = player.b;
}
- if (opt.tech->level > player.level) {
- r = 100; g = 100; b = 100;
- }
- if (opt.tech->cost[0] > player.res[0]
- || opt.tech->cost[1] > player.res[1] )
- {
+ if (!gst.check_req_tech(opt.tech, player)) {
r = 100; g = 100; b = 100;
}
- bool req_id = false;
- for (auto &ent : gst.entities) {
- if (ent.owner == gst.turn
- && ent.info->id == opt.tech->req_id
- && ent.building == 0)
- {
- req_id = true;
- }
- }
- if (!req_id) {
- r = 100; g = 100; b = 100;
+ if (player.has_tech(opt.tech->id)) {
+ r = constants::col_gud_r;
+ g = constants::col_gud_g;
+ b = constants::col_gud_b;
}
graphics->backend.txt.render_text(opt.name,
view.menu_tech.pos + vec2 {10 + x, 10 + y}, r, g, b);
@@ -144,6 +143,9 @@ int get_entity_info_height (Entity &ent) {
void render_entity_info (Graphics *graphics, Gst &gst, vec2 pos, int i) {
Entity &ent = gst.entities[i];
+ Player &player = gst.players[ent.owner];
+ auto &tech = player.tech_lookup;
+ int id = ent.info->id;
int w = 200, h = get_entity_info_height(ent);
graphics->backend.render_rect (0,0,0,255,
@@ -156,29 +158,29 @@ void render_entity_info (Graphics *graphics, Gst &gst, vec2 pos, int i) {
graphics->backend.render_rect (
255,255,255,255, (int)pos.x+w-32-10, (int)pos.y+10,32,32);
- graphics->backend.render_sprite (
- (int)gst.entities[i].info->spritebounds.x,
- (int)gst.entities[i].info->spritebounds.y, 16, 16,
- (int)pos.x + w-32-10,
- (int)pos.y + 10, 32, 32
- );
+ render_ent(graphics, gst, ent, vec2 { w-32-10.0f, 10 } + pos, 0);
graphics->backend.txt.render_text(ent.info->name, pos + vec2 { 10, 10 });
graphics->backend.txt.render_text("Attack", pos + vec2 { 10, 30 });
+ float attack = ent.info->attack * (1+tech.id(id).attack);
graphics->backend.txt.render_text(
- std::to_string((int)roundf(ent.info->attack)), pos + vec2 { 90, 30 });
+ std::to_string((int)roundf(attack)), pos + vec2 { 90, 30 });
graphics->backend.txt.render_text("Defence", pos + vec2 { 10, 45 });
+ float defence = ent.info->defence * (1+tech.id(id).defence);
graphics->backend.txt.render_text(
- std::to_string((int)roundf(ent.info->defence)), pos + vec2 { 90, 45 });
+ std::to_string((int)roundf(defence)), pos + vec2 { 90, 45 });
graphics->backend.txt.render_text("Move", pos + vec2 { 10, 60 });
+ int move = ent.info->move + tech.id(id).move;
graphics->backend.txt.render_text(
- std::to_string((int)roundf(ent.info->move)), pos + vec2 { 90, 60 });
+ std::to_string(move), pos + vec2 { 90, 60 });
graphics->backend.txt.render_text("Range", pos + vec2 { 10, 75 });
+ int range = ent.info->range + tech.id(id).range;
graphics->backend.txt.render_text(
- std::to_string((int)roundf(ent.info->range)), pos + vec2 { 90, 75 });
+ std::to_string(range), pos + vec2 { 90, 75 });
graphics->backend.txt.render_text("Sight", pos + vec2 { 10, 90 });
+ int sight = ent.info->sight + tech.id(id).sight;
graphics->backend.txt.render_text(
- std::to_string((int)roundf(ent.info->sight)), pos + vec2 { 90, 90 });
+ std::to_string(sight), pos + vec2 { 90, 90 });
graphics->backend.txt.render_text("Health", pos + vec2 { 10, 105 });
graphics->backend.txt.render_text(
std::to_string((int)roundf(ent.hp)), pos + vec2 { 90, 105 });
@@ -499,6 +501,8 @@ void Graphics::render (Gst &gst, View &view)
render_menu(this, gst, view.menu_day);
render_menu(this, gst, view.menu_build);
render_menu(this, gst, view.menu_train);
+ render_menu(this, gst, view.menu_trade);
+ render_menu(this, gst, view.menu_age_up);
render_menu_tech(this, gst, view);
if (view.moves.size() > 0) {
@@ -534,15 +538,19 @@ void Graphics::render (Gst &gst, View &view)
player.r, player.g, player.b, 255,
(int)pos.x+5,(int)pos.y+5, 20, 20
);
-
- std::string txtfood = std::to_string (player.res[0]) + "f";
- std::string txtgold = std::to_string (player.res[1]) + "g";
+ std::string txtfood = std::to_string((int)roundf(player.res[0])) + "f";
+ std::string txtgold = std::to_string((int)roundf(player.res[1])) + "g";
backend.txt.render_text(
txtfood, pos + vec2 { -backend.txt.get_width(txtfood) + res.x/2-10, 10 }
);
- backend.txt.render_text(
- txtgold, pos + vec2 { res.x/2+10, 10 }
- );
+ backend.txt.render_text(txtgold, pos + vec2 { res.x/2+10, 10 });
+ std::string txtres = "Researching: ";
+ if (player.researching != -1) {
+ txtres += gst.get_tech(player.researching)->name;
+ } else { txtres += "None"; }
+ float reswidth = backend.txt.get_width(txtres);
+ backend.txt.render_text(txtres, pos + vec2 { res.x-reswidth-10, 10 });
+
// low bar
backend.render_rect (
255,255,255,255,
diff --git a/main.cpp b/main.cpp
index d7a0cca..658bcd4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -58,10 +58,10 @@ int main () {
load_json(gst);
- gst.players.emplace_back(255, 0, 0);
- gst.players[0].res = std::vector<int> { 1500, 1500 };
- gst.players.emplace_back(0, 0, 255);
- gst.players[1].res = std::vector<int> { 1500, 1500 };
+ gst.players.emplace_back(255, 0, 0, 0);
+ gst.players[0].res = std::vector<float> { 1500, 1500 };
+ gst.players.emplace_back(0, 0, 255, 1);
+ gst.players[1].res = std::vector<float> { 1500, 1500 };
gst.ground.tiles[1] = 1;
gst.ground.tiles[8] = 1;
@@ -81,6 +81,8 @@ int main () {
gst.entities.emplace_back(5, 1, gst.get_info("Town Center"), 0);
+ gst.entities.emplace_back(6, 1, gst.get_info("Barracks"), 0);
+ gst.entities.emplace_back(5, 0, gst.get_info("Stable"), 0);
gst.entities.emplace_back(1, 1, gst.get_info("Villager"), 0);
gst.entities.emplace_back(2, 1, gst.get_info("Light Cavalry"), 0);
gst.entities.emplace_back(10, 10, gst.get_info("Villager"), 1);
diff --git a/notes.txt b/notes.txt
new file mode 100644
index 0000000..e1a36de
--- /dev/null
+++ b/notes.txt
@@ -0,0 +1,30 @@
+[x] level restrict train and build
+[x] current tech gui
+[x] tech bonus addition
+[x] some tech effects
+[x] tc and market trade
+[x] age up menu
+[x] end day upgrade on age up
+[x] end day heal when on bld
+[ ] bld ages upgrades
+[ ] train problem
+[ ] heal
+[ ] convert
+[ ] relics
+[ ] tower diagonal constraint
+[ ] tower defence effect -> new bonus type
+[ ] castle
+[ ] veterancy ranks
+[ ] frenzy special case
+[ ] gui production
+[ ] gui train build
+[ ] tech effects
+[ ] unit tech requirement (paladin, champion, imp siege)
+[ ] fsm back
+[ ] undo
+
+[ ] imp unit sprites
+[x] sprites stable, castle, uni, market, church, tower and bld upgrade
+
+[ ] wheelbarrow doesn't work
+[ ] search player by id, not by index \ No newline at end of file