new setup system
authorNiki Roo <niki@nikiroo.be>
Tue, 15 Apr 2025 12:28:02 +0000 (14:28 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 15 Apr 2025 12:28:02 +0000 (14:28 +0200)
src/tdef/engine.c
src/tdef/engine.h
src/tdef/map.c
src/tdef/map.h
src/tdef/setup.c [new file with mode: 0644]
src/tdef/setup.h [new file with mode: 0644]
src/tdef/tdef.c

index e2f23a33b4fbd9fce2e639faa7c2cef2f1d1ae8e..bee6dddcb2c9b75b91480ad1fa08fa2051361179 100644 (file)
@@ -162,52 +162,3 @@ tower_base_t *engine_get_tower_base(engine_t *self, int type) {
        return NULL;
 }
 
-tower_base_t *setup_tower_base(engine_t *self, int type, int cost) {
-       tower_base_t *base = engine_get_tower_base(self, type);
-       if (base) // already configured
-               return NULL;
-       
-       base = array_new(self->tbases);
-       init_tower_base(base, type);
-       base->cost = cost;
-       return base;
-}
-
-int setup_wave(engine_t *self, int start_tick, int bits) {
-       wave_t *wave = array_new(self->waves);
-       if (!wave)
-               return 0;
-       
-       init_wave(wave, start_tick);
-       wave->bits = bits;
-       
-       return 1;
-}
-
-enemy_t *setup_enemy(engine_t *self, int type, int id, size_t start_tick) {
-       if (!self->waves->count)
-               if (!setup_wave(self, 0, 0))
-                       return 0;
-       
-       //TODO: type and eney_base_t
-       
-       wave_t *wave = array_last(self->waves);
-       return wave_add_enemy(wave, id, start_tick);
-}
-
-int setup_path(engine_t *self, int x, int y) {
-       if (x < 0 || y < 0)
-               return 0;
-       if (x >= self->map->width || y >= self->map->height)
-               return 0;
-       if (self->map->data[y * self->map->width + x])
-               return 0;
-
-       path_t *loc = array_new(self->map->paths);
-       init_path(loc, x, y);
-       loc->index = self->map->paths->count - 1;
-
-       self->map->data[y * self->map->width + x] = path2any(loc);
-       return 1;
-}
-
index 0de52a1e8a6a4348b8e650f56f59e2a9d0eafef6..cd97f0249fc74278f39823773c422cf24818b247 100644 (file)
@@ -87,13 +87,5 @@ int engine_add_tower(engine_t *self, int type, int x, int y);
 
 tower_base_t *engine_get_tower_base(engine_t *self, int type);
 
-tower_base_t *setup_tower_base(engine_t *self, int type, int cost);
-
-int setup_wave(engine_t *self, int start_tick, int bits);
-
-enemy_t *setup_enemy(engine_t *self, int type, int id, size_t start_tick);
-
-int setup_path(engine_t *self, int x, int y);
-
 #endif /* ENGINE_H */
 
index 811a73558575a05d10e8add92f61f6b3875c2002..5cf7a17025c07a219cfea5007193a1cca17f0f4d 100644 (file)
@@ -97,6 +97,25 @@ void uninit_map(map_t *self) {
        }
 }
 
+int map_add_path(map_t *self, int x, int y) {
+       if (x < 0 || y < 0)
+               return 0;
+       if (x >= self->width || y >= self->height)
+               return 0;
+       if (self->data[y * self->width + x])
+               return 0;
+
+       path_t *loc = array_new(self->paths);
+       if (!loc)
+               return 0;
+       
+       init_path(loc, x, y);
+       loc->index = self->paths->count - 1;
+
+       self->data[y * self->width + x] = path2any(loc);
+       return 1;
+}
+
 void map_enemy_enters(map_t *self, enemy_t *enemy, array_t *events) {
        enemy->alive = 1;
        array_push(self->alive, &enemy);
index a6f041629d26d0eaef68d8fadc3ef8d139c9de85..b8e83c2ab031c9d727765fe71b8b5ed70f8f07e7 100644 (file)
@@ -79,6 +79,8 @@ void free_map(map_t *self);
  */
 void uninit_map(map_t *self);
 
+int map_add_path(map_t *self, int x, int y);
+
 void map_enemy_enters(map_t *self, enemy_t *enemy, array_t *events);
 
 void map_move_1(map_t *self, array_t *events);
diff --git a/src/tdef/setup.c b/src/tdef/setup.c
new file mode 100644 (file)
index 0000000..c75989a
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * TDef: small tower defense game
+ *
+ * Copyright (C) 2025 Niki Roo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "setup.h"
+
+tower_base_t *setup_tower_base(engine_t *self, int type, int cost) {
+       tower_base_t *base = engine_get_tower_base(self, type);
+       if (base) // already configured
+               return NULL;
+       
+       base = array_new(self->tbases);
+       init_tower_base(base, type);
+       base->cost = cost;
+       
+       return base;
+}
+
+int setup_wave(engine_t *self, int start_tick, int bits) {
+       wave_t *wave = array_new(self->waves);
+       if (!wave)
+               return 0;
+       
+       init_wave(wave, start_tick);
+       wave->bits = bits;
+       
+       return 1;
+}
+
+enemy_t *setup_enemy(engine_t *self, int type, int id, size_t start_tick) {
+       if (!self->waves->count)
+               if (!setup_wave(self, 0, 0))
+                       return 0;
+       
+       //TODO: type and eney_base_t
+       
+       wave_t *wave = array_last(self->waves);
+       return wave_add_enemy(wave, id, start_tick);
+}
+
+int setup_path(engine_t *self, int x, int y) {
+       return map_add_path(self->map, x, y);
+}
+
diff --git a/src/tdef/setup.h b/src/tdef/setup.h
new file mode 100644 (file)
index 0000000..fc74b98
--- /dev/null
@@ -0,0 +1,25 @@
+/** 
+ * @file setup.h
+ * @author Niki
+ * @date 2025
+ * 
+ * @brief bla
+ *
+ * blablabla
+ *
+ */
+
+#ifndef SETUP_H
+#define SETUP_H
+
+#include "engine.h"
+
+tower_base_t *setup_tower_base(engine_t *self, int type, int cost);
+
+int setup_wave(engine_t *self, int start_tick, int bits);
+
+enemy_t *setup_enemy(engine_t *self, int type, int id, size_t start_tick);
+
+int setup_path(engine_t *self, int x, int y);
+
+#endif /* SETUP_H */
index 14319adf840a16e676a4cec27031575352ef4ed4..8d7cf14e3531cc5543d9f6d19a34b08a558dcd87 100644 (file)
@@ -26,6 +26,8 @@
 #include "engine.h"
 #include "reader.h"
 #include "event.h"
+#include "command.h"
+#include "setup.h"
 
 int displayMode = 0;