Implement a very rough outline of the program
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sat, 8 Jun 2024 11:36:05 +0000 (13:36 +0200)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sat, 8 Jun 2024 11:36:05 +0000 (13:36 +0200)
Makefile [new file with mode: 0644]
inc/railnation_calc.h [new file with mode: 0644]
src/main.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..be8c4fa
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,51 @@
+CC := gcc
+CFLAGS = -std=c99 -Wall -Wextra -Werror -Wpedantic
+
+RM := rm -f
+
+SUBPROJECTS := Libft
+
+INCDIR := inc
+INCDIR += $(addsuffix /inc, $(SUBPROJECTS));
+INCLUDE := $(addprefix -I, $(INCDIR))
+
+SRCDIR := src
+
+SOURCES :=     main.c                  \
+
+SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))
+
+OBJECTS := $(SOURCES:.c=.o)
+
+NAME := railnation_calc
+
+all : $(NAME)
+
+debug : CFLAGS += -g
+debug : $(NAME)
+
+$(NAME) : $(OBJECTS) Libft/libft.a
+       $(CC) $(CFLAGS) -o $@ $^
+
+Libft/libft.a : | Libft/Makefile
+ifneq (,$(findstring debug, $(MAKECMDGOALS)))
+       $(MAKE) -C Libft debug
+else
+       $(MAKE) -C Libft
+endif
+
+%.o : %.c | Libft/Makefile
+       $(CC) $(CFLAGS) -o $@ -c $< $(INCLUDE)
+
+%/Makefile :
+       git submodule update --init $($@%/Makefile=%)
+
+clean :
+       $(RM) $(OBJECTS)
+
+fclean : clean
+       $(MAKE) -C Libft/ fclean
+       $(RM) $(NAME)
+
+re : fclean
+       $(MAKE) all
diff --git a/inc/railnation_calc.h b/inc/railnation_calc.h
new file mode 100644 (file)
index 0000000..36f4eaa
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef RAILNATION_CALC_H
+# define RAILNATION_CALC_H
+
+# include "libft.h"
+
+# define ERA_COUNT 6
+
+typedef struct s_train_characteristics
+{
+       unsigned short  era;
+       unsigned short  size;
+       unsigned short  capacity;
+       unsigned short  reliability;
+       unsigned short  acceleration;
+       unsigned short  top_speed;
+       unsigned short  research_cost;
+       unsigned int    price;
+}                                      t_train_characteristics;
+
+typedef struct s_upgrade
+{
+       char                                    *name;
+       t_train_characteristics characteristics;
+}                                                      t_upgrade;
+
+typedef struct s_train
+{
+       char                                    *name;
+       t_train_characteristics base;
+       t_vec                                   upgrades;
+}                                                      t_train;
+
+#endif //RAILNATION_CALC_H
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..7320e2c
--- /dev/null
@@ -0,0 +1,16 @@
+#include "railnation_calc.h"
+#include "libft.h"
+
+#define DATABASE_FILE_NAME "research.csv"
+
+int    main(void)
+{
+       const t_vec catalog = load_catalog(DATABASE_FILE_NAME);
+       t_vec           trains;
+
+       ft_vec_init(&trains, sizeof(t_train));
+       while (main_prompt(&catalog, &train));
+       ft_vec_free(&trains, free_train);
+       free_catalog(&catalog);
+       return (0);
+}