Debug ai, fix Makefile
This commit is contained in:
parent
197e8d4c1b
commit
0021354346
2 changed files with 32 additions and 16 deletions
11
Makefile
11
Makefile
|
@ -1,6 +1,6 @@
|
|||
OUTNAME = mtycoon
|
||||
|
||||
CFLAGS = -O2 -g -Wall -Wextra -I ./raylib/include
|
||||
CFLAGS = -O0 -g -Wall -Wextra -I ./raylib/include
|
||||
#linux
|
||||
#LDFLAGS = -static -L./raylib/lib -lraylib -lm
|
||||
#windows
|
||||
|
@ -17,7 +17,12 @@ $(BUILD_DIR)/%.o : $(SRC_DIR)/%.c
|
|||
|
||||
OBJS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c))
|
||||
|
||||
all: $(OBJS)
|
||||
builddir:
|
||||
- mkdir $(BUILD_DIR)
|
||||
|
||||
build: $(OBJS)
|
||||
|
||||
all: | builddir build
|
||||
${CC} ${CFLAGS} -o ${OUTPUT} ${OBJS} ${LDFLAGS}
|
||||
|
||||
win: all
|
||||
|
@ -30,6 +35,6 @@ test: all
|
|||
./${OUTPUT}
|
||||
|
||||
clean:
|
||||
rm -rf ${BUILD_DIR}/*
|
||||
rm -rf ${BUILD_DIR}
|
||||
|
||||
.PHONY: all test clean win testwin prodwin
|
||||
|
|
37
src/main.c
37
src/main.c
|
@ -170,7 +170,7 @@ Worker *add_worker(Workers *workers, V2d pos){
|
|||
|
||||
Worker *work = &workers->worker_stack[workers->worker_n++];
|
||||
work->pos = pos;
|
||||
work->ai = (AiInternal){S_Idle, 0, 0, 0, -1, -1};
|
||||
work->ai = (AiInternal){S_Idle, 0, 0, 0, -1, -1, {.x=0,.y=0}};
|
||||
|
||||
return work;
|
||||
}
|
||||
|
@ -201,7 +201,8 @@ int id_cmpfunc(const void *a_, const void *b_){
|
|||
}
|
||||
|
||||
Machine *get_machine_from_id(Machines *machines, int id){
|
||||
Machine *match = bsearch(&id, machines->machine_stack, machines->machine_n,
|
||||
Machine tmach = {.id = id};
|
||||
Machine *match = bsearch(&tmach, machines->machine_stack, machines->machine_n,
|
||||
sizeof(Machine), &id_cmpfunc);
|
||||
return match;
|
||||
}
|
||||
|
@ -227,19 +228,19 @@ void update_worker(Game *game, Worker *worker){
|
|||
mach[0] = get_machine_from_id(&game->machines, ai->assigned_machine);
|
||||
if(!mach[0])
|
||||
ai->assigned_machine = -1;
|
||||
else
|
||||
defs[0] = &machine_dict[mach[0]->type];
|
||||
}
|
||||
if(ai->assigned_machine1 > -1){
|
||||
mach[1] = get_machine_from_id(&game->machines, ai->assigned_machine1);
|
||||
if(!mach[1])
|
||||
ai->assigned_machine1 = -1;
|
||||
else
|
||||
defs[1] = &machine_dict[mach[1]->type];
|
||||
}
|
||||
|
||||
if(ai->assigned_machine < 0 && ai->assigned_machine1 < 0)
|
||||
ai->status = S_Idle;
|
||||
else {
|
||||
defs[0] = &machine_dict[mach[0]->type];
|
||||
defs[1] = &machine_dict[mach[1]->type];
|
||||
}
|
||||
|
||||
//TODO : Move !
|
||||
switch(ai->status){
|
||||
|
@ -286,6 +287,7 @@ void update_worker(Game *game, Worker *worker){
|
|||
}
|
||||
break;
|
||||
case S_Operating:
|
||||
worker->pos = mach[0]->pos;
|
||||
break;
|
||||
case S_Transporting:
|
||||
case S_Walking:
|
||||
|
@ -317,8 +319,8 @@ void draw_machines(Machines *machines){
|
|||
}
|
||||
|
||||
void draw(Game *game){
|
||||
draw_workers(&game->workers);
|
||||
draw_machines(&game->machines);
|
||||
draw_workers(&game->workers);
|
||||
}
|
||||
|
||||
int assign_worker_machine(Machine *machine, Worker *worker){
|
||||
|
@ -326,13 +328,16 @@ int assign_worker_machine(Machine *machine, Worker *worker){
|
|||
AiInternal *ai = &worker->ai;
|
||||
ai->assigned_machine = machine->id;
|
||||
ai->assigned_machine1 = -1;
|
||||
ai->status = S_Operating;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int assign_worker_fetch(Machine *a, Machine *b, Worker *worker){
|
||||
AiInternal *ai = &worker->ai;
|
||||
ai->carry_type = machine_dict[a->id].output;
|
||||
ai->assigned_machine = a->id;
|
||||
ai->assigned_machine1 = b->id;
|
||||
ai->status = S_Transporting;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -347,7 +352,7 @@ int main(){
|
|||
|
||||
srand(rand_seed);
|
||||
|
||||
InitWindow(800, 600, "Mineur Tycoon");
|
||||
InitWindow(1280, 720, "Mineur Tycoon");
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
|
@ -357,14 +362,20 @@ int main(){
|
|||
|
||||
Machine *coal_mine = add_machine(&game.machines, (V2d){40,40});
|
||||
coal_mine->type = MT_CoalMine;
|
||||
Machine *iron_mine = add_machine(&game.machines, (V2d){40,240});
|
||||
iron_mine->type = MT_IronMine;
|
||||
Machine *furnace = add_machine(&game.machines, (V2d){140,140});
|
||||
furnace->type = MT_Furnace;
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
add_worker(&game.workers, (V2d){.x=100,.y=100});
|
||||
for(int i = 0; i < 4; i++)
|
||||
assign_worker_machine(coal_mine, &game.workers.worker_stack[i]);
|
||||
for(int i = 4; i < 8; i++)
|
||||
assign_worker_machine(iron_mine, &game.workers.worker_stack[i]);
|
||||
assign_worker_fetch(iron_mine, furnace, &game.workers.worker_stack[8]);
|
||||
assign_worker_fetch(coal_mine, furnace, &game.workers.worker_stack[9]);
|
||||
|
||||
assign_worker_machine(coal_mine, &game.workers.worker_stack[0]);
|
||||
assign_worker_machine(coal_mine, &game.workers.worker_stack[1]);
|
||||
assign_worker_machine(coal_mine, &game.workers.worker_stack[2]);
|
||||
assign_worker_machine(coal_mine, &game.workers.worker_stack[3]);
|
||||
|
||||
while(!WindowShouldClose()){
|
||||
BeginDrawing();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue