MarioPartyMaker/src/assembly.c

161 lines
4.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <stdbool.h>
#include <ncurses.h>
#include <unistd.h>
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "consts.h"
#include "base.h"
#include "display.h"
#include "assembly.h"
void init_empty_board() {
start = malloc(sizeof(cell));
start->id = 0 ;
start->coord_x = 50 ;
start->coord_y = 50 ;
start->star_allowed = false ;
start->type = START ;
start->prev_1 = start;
start->prev_2 = NULL;
start->prev_3 = NULL;
start->prev_4 = NULL;
start->next_1 = start;
start->next_2 = NULL;
start->next_3 = NULL;
start->next_4 = NULL;
start->meta = "start";
}
void init_players() {
players = malloc(sizeof(player)*n_players);
for(int i = 0; i < n_players; i++) {
players[i].name = "player" ;
players[i].standing_tile = start ;
players[i].coins = 10 ;
players[i].stars = 0 ;
players[i].items = malloc(sizeof(ITEM)*3) ;
players[i].max_items = 3 ;
players[i].item_len = 0 ;
players[i].stats.minigames_wins = 0;
players[i].stats.coin_collected = 0 ;
players[i].stats.red_count = 0 ;
players[i].stats.bowser_count = 0 ;
players[i].stats.items_used = 0 ;
players[i].stats.lost_coins = 0 ;
players[i].stats.lost_stars = 0 ;
players[i].stats.tiles_travelled = 0 ;
players[i].stats.events_triggered = 0 ;
players[i].stats.hidden_blocks = 0 ;
}
}
void init_shop(char* filename) {
item_costs = malloc(sizeof(int)*n_items);
item_start = malloc(sizeof(int)*n_items) ;
item_end = malloc(sizeof(int)*n_items) ;
item_is_normal_type = malloc(sizeof(bool)*n_items) ;
item_is_special_type = malloc(sizeof(bool)*n_items) ;
FILE* ptr = fopen(filename, "r");
if(ptr == NULL) {
fprintf(stderr, "ERROR : unable to load config file %s\n", filename);
exit(1);
} else {
printf(" Loading %s...\n", filename);
}
int buffer = -1 ;
int index = 0 ;
int sub_index = 0 ;
char c = fgetc(ptr);
bool is_reading = false ;
bool ignore_line = false ;
while(c != EOF && c != '$') {
if(!ignore_line) {
if(c == '{') {
is_reading = true;
} else if(c == '}') {
is_reading = false;
sub_index = 0;
} else if(c == '*') {
ignore_line = true;
} else if(c == ':') {
buffer = 0;
} else if(is_reading && buffer != -1) {
if(is_an_integer(c)) {
buffer *= 10;
buffer += (char)c - 48;
} else {
if(sub_index == 0) {
index = buffer;
} else if(sub_index == 1) {
item_start[index] = buffer;
} else if(sub_index == 2) {
item_end[index] = n_turns - buffer;
} else if(sub_index == 3) {
item_costs[index] = buffer;
} else if(sub_index == 4) {
item_is_normal_type[index] = (bool)buffer;
} else if(sub_index == 5) {
item_is_special_type[index] = (bool)buffer;
};
sub_index += 1;
buffer = -1;
}
}
};
if(c == '\n') {
ignore_line = false;
};
c = fgetc(ptr);
};
fclose(ptr);
}
void init_everything() {
printf("Initializing board...\n");
init_empty_board();
printf("Initializing players...\n");
init_players();
printf("Initializing items...\n");
init_shop("src/config.txt");
printf("Initialization complete...\n");
//print_items();
}
void print_items() {
for(int i = 0; i < n_items; i++) {
printf("Item : %d\n", i);
printf("cost : %d\nTurns : [%d - %d]\ntypes=[N = %d , S = %d]", item_costs[i], item_start[i], item_end[i], item_is_normal_type[i], item_is_special_type[i]);
printf("\n\n");
}
}
void destroy_everything() {
for(int i = 0; i < n_players; i++) {
free(players[i].items);
};
free(players);
free(item_costs);
free(item_start);
free(item_end);
free(item_is_normal_type);
free(item_is_special_type);
free(cell_count);
}
#include "consts.h"
#include "assembly.h"