mirror of
https://github.com/zoriya/ForecastingVillage.git
synced 2026-06-01 02:08:14 +00:00
Merge branch 'master' of github.com:AnonymusRaccoon/ForecastingVillage
This commit is contained in:
+1
-1
@@ -297,7 +297,7 @@ add_executable(my_rpg
|
||||
src/components/attack_component.c
|
||||
include/components/attack_component.h
|
||||
src/systems/combat_methods.c
|
||||
src/combat/fireball.c
|
||||
src/combat/attacks.c
|
||||
src/player_utilities.c include/player_utilities.h)
|
||||
|
||||
add_compile_options(-W -Wall -Wextra -Wshadow)
|
||||
|
||||
@@ -20,6 +20,7 @@ struct dialog_line {
|
||||
char *text;
|
||||
int input_count;
|
||||
struct dialog_input *inputs;
|
||||
void (*callback)(gc_engine *engine);
|
||||
};
|
||||
|
||||
struct dialog_holder {
|
||||
@@ -46,8 +47,8 @@ struct dialog_manager {
|
||||
const struct dialog_manager dialog_manager;
|
||||
|
||||
void dialog_next(gc_engine *engine);
|
||||
void dialog_add_line(struct dialog_holder *this, char *name, char *text, \
|
||||
struct dialog_input *inputs);
|
||||
struct dialog_line *dialog_add_line(struct dialog_holder *this, char *name, \
|
||||
char *text, struct dialog_input *inputs);
|
||||
void show_dialog_if_hidden(gc_engine *engine);
|
||||
|
||||
#endif //MY_RPG_DIALOG_HOLDER_H
|
||||
|
||||
@@ -56,5 +56,8 @@ enum gc_mousekeys key);
|
||||
gc_data *enemies_dataloader(gc_engine *engine, gc_scene *scene, node *n);
|
||||
|
||||
void fireball(gc_engine *engine, gc_entity *from, gc_entity *enemy);
|
||||
void uppercut(gc_engine *engine, gc_entity *from, gc_entity *enemy);
|
||||
void water_jet(gc_engine *engine, gc_entity *from, gc_entity *enemy);
|
||||
void shield(gc_engine *engine, gc_entity *from, gc_entity *enemy);
|
||||
|
||||
void load_attacks(gc_scene *scene);
|
||||
@@ -9,6 +9,7 @@
|
||||
#ifndef MY_RPG_COMBAT_MANAGER_H
|
||||
#define MY_RPG_COMBAT_MANAGER_H
|
||||
|
||||
#include <components/attack_component.h>
|
||||
#include "system.h"
|
||||
#include "components/combat_holder.h"
|
||||
#include "components/dialog_holder.h"
|
||||
@@ -26,6 +27,7 @@ struct combat_manager {
|
||||
gc_system base;
|
||||
gc_scene *game_scene;
|
||||
struct enemy *current_enemy;
|
||||
struct attack_holder *next_enemy_attack;
|
||||
enum combat_state state;
|
||||
};
|
||||
|
||||
@@ -34,6 +36,7 @@ extern const struct combat_manager combat_manager;
|
||||
#define ATTACK_TEXT "What attack will you do?"
|
||||
|
||||
void combat_start(gc_engine *engine, char *enemy_name);
|
||||
void combat_end(gc_engine *engine, bool has_won);
|
||||
void show_attacks(struct combat_manager *this, struct dialog_holder *dialog, \
|
||||
gc_scene *scene, gc_engine *engine);
|
||||
void defend(struct combat_manager *this, struct dialog_holder *dialog, \
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
<map_linker x="0" y="0" />
|
||||
<player_component />
|
||||
<attack_component>
|
||||
<attack name="Wind Slash" />
|
||||
<attack name="Blizzard" />
|
||||
<attack name="Uppercut" />
|
||||
<attack name="Water grenade" />
|
||||
<attack name="Fireball" />
|
||||
<attack name="Water jet" />
|
||||
<attack name="Shield" />
|
||||
</attack_component>
|
||||
<xp_component xp="3"/>
|
||||
<health_component max_health="3"/>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** fireball.c
|
||||
*/
|
||||
|
||||
#include <components/health_component.h>
|
||||
#include "engine.h"
|
||||
|
||||
void uppercut(gc_engine *engine, gc_entity *from, gc_entity *enemy)
|
||||
{
|
||||
struct health_component *enemy_health = GETCMP(enemy, health_component);
|
||||
|
||||
rem_health(enemy_health, engine, 10);
|
||||
}
|
||||
|
||||
void water_jet(gc_engine *engine, gc_entity *from, gc_entity *enemy)
|
||||
{
|
||||
printf("water_grenade\n");
|
||||
}
|
||||
|
||||
void fireball(gc_engine *engine, gc_entity *from, gc_entity *enemy)
|
||||
{
|
||||
printf("FIREBALL\n");
|
||||
}
|
||||
|
||||
void shield(gc_engine *engine, gc_entity *from, gc_entity *enemy)
|
||||
{
|
||||
printf("shield\n");
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** fireball.c
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
void fireball(gc_engine *engine, gc_entity *from, gc_entity *enemy)
|
||||
{
|
||||
printf("FIREBALL\n");
|
||||
}
|
||||
@@ -65,7 +65,8 @@ struct dialog_line *dialog_parse_text(gc_scene *scene, node *n)
|
||||
return (NULL);
|
||||
txt->name = my_strdup(n->name);
|
||||
txt->text = xml_getproperty(n, "line");
|
||||
txt->input_count = xml_getchildcount_filtered(n, "input");;
|
||||
txt->input_count = xml_getchildcount_filtered(n, "input");
|
||||
txt->callback = NULL;
|
||||
txt->inputs = NULL;
|
||||
if (txt->input_count == 0)
|
||||
return (txt);
|
||||
|
||||
@@ -9,25 +9,27 @@
|
||||
#include "utility.h"
|
||||
#include <malloc.h>
|
||||
|
||||
void dialog_add_line(struct dialog_holder *this, char *name, char *text, \
|
||||
struct dialog_line *dialog_add_line(struct dialog_holder *this, char *name, char *text, \
|
||||
struct dialog_input *inputs)
|
||||
{
|
||||
struct dialog_line *line = malloc(sizeof(*line));
|
||||
int count = 0;
|
||||
|
||||
if (!line)
|
||||
return;
|
||||
return (NULL);
|
||||
line->name = name;
|
||||
line->text = text;
|
||||
if (inputs)
|
||||
for (count = 0; inputs[count].text; count++);
|
||||
line->input_count = count;
|
||||
line->inputs = inputs;
|
||||
line->callback = NULL;
|
||||
for (count = 0; this->text[count]; count++);
|
||||
this->text = my_realloc(this->text, (count + 1) * sizeof(void *), \
|
||||
(count + 2) * sizeof(void *));
|
||||
if (!this->text)
|
||||
return;
|
||||
return (NULL);
|
||||
this->text[count] = line;
|
||||
this->text[count + 1] = NULL;
|
||||
return (line);
|
||||
}
|
||||
@@ -62,13 +62,18 @@ const struct callback map_editor_callbacks[] = {
|
||||
};
|
||||
|
||||
const struct gc_data attacks[] = {
|
||||
{"attack", "Uppercut", &uppercut, NULL},
|
||||
{"attack", "Fireball", &fireball, NULL},
|
||||
{"attack", "Water Jet", &water_jet, NULL},
|
||||
{"attack", "Shield", &shield, NULL},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
void load_attacks(gc_scene *scene)
|
||||
{
|
||||
gc_data *data;
|
||||
gc_list *li = scene->get_entity_by_cmp(scene, "attack_component");
|
||||
struct attack_component *attack;
|
||||
|
||||
for (int i = 0; attacks[i].name; i++) {
|
||||
data = malloc(sizeof(*data));
|
||||
@@ -80,6 +85,12 @@ void load_attacks(gc_scene *scene)
|
||||
data->destroy = attacks[i].destroy;
|
||||
LISTADD(scene->data, data);
|
||||
}
|
||||
for (; li; li = li->next) {
|
||||
attack = GETCMP(li->data, attack_component);
|
||||
for (int i = 0; attack->attacks && attack->attacks[i].name; i++)
|
||||
attack->attacks[i].run = scene->get_data(scene, "attack", \
|
||||
attack->attacks[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
int register_customcmps(gc_engine *engine, bool map_editor)
|
||||
|
||||
@@ -29,20 +29,22 @@ void entity_moved(gc_engine *engine, va_list args)
|
||||
combat_start(engine, NULL);
|
||||
}
|
||||
|
||||
void dialog_ended(gc_engine *engine, va_list args)
|
||||
void combat_end(gc_engine *engine, bool has_won)
|
||||
{
|
||||
struct combat_manager *this = GETSYS(engine, combat_manager);
|
||||
gc_entity *player = engine->scene->get_entity(engine->scene, 50);
|
||||
gc_entity *player_combat = this->game_scene->get_entity(this->game_scene, 50);
|
||||
struct dialog_manager *dialog = GETSYS(engine, dialog_manager);
|
||||
|
||||
if (!this->current_enemy || !player || ! player_combat)
|
||||
if (!this->current_enemy || !player || ! player_combat || !dialog)
|
||||
return;
|
||||
set_combat_player(player_combat, player);
|
||||
engine->trigger_event(engine, "combat_ended", this->current_enemy);
|
||||
this->current_enemy = NULL;
|
||||
engine->change_scene(engine, this->game_scene);
|
||||
engine->trigger_event(engine, "combat_ended", this->current_enemy, has_won);
|
||||
this->game_scene = NULL;
|
||||
this->state = ATTACK;
|
||||
dialog->dialog_id = -1;
|
||||
}
|
||||
|
||||
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
|
||||
@@ -76,7 +78,6 @@ static void ctr(void *system, va_list list)
|
||||
this->game_scene = NULL;
|
||||
this->state = ATTACK;
|
||||
engine->add_event_listener(engine, "entity_moved", &entity_moved);
|
||||
engine->add_event_listener(engine, "dialog_ended", &dialog_ended);
|
||||
}
|
||||
|
||||
static void dtr(void *system, gc_engine *engine)
|
||||
@@ -84,7 +85,6 @@ static void dtr(void *system, gc_engine *engine)
|
||||
struct combat_manager *this = system;
|
||||
|
||||
engine->remove_event_listener(engine, "entity_moved", &entity_moved);
|
||||
engine->remove_event_listener(engine, "dialog_ended", &dialog_ended);
|
||||
if (this->game_scene)
|
||||
scene_destroy(this->game_scene);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ void combat_start(gc_engine *engine, char *enemy_name)
|
||||
my_printf("The combat scene couldn't be found.\n");
|
||||
return;
|
||||
}
|
||||
this->state = ATTACK;
|
||||
this->game_scene = engine->scene;
|
||||
set_combat_player(player, player_combat);
|
||||
engine->scene = NULL;
|
||||
@@ -77,8 +78,9 @@ void attack_callback(gc_engine *engine, int index)
|
||||
|
||||
if (!li || !get_player_and_enemy(scene, &player_entity, &enemy))
|
||||
return;
|
||||
player = GETCMP(player_entity, attack_component);
|
||||
if (!player)
|
||||
if (GETCMP(player_entity, health_component)->dead)
|
||||
combat_end(engine, false);
|
||||
if (!(player = GETCMP(player_entity, attack_component)))
|
||||
return;
|
||||
if (player->attacks[index].run)
|
||||
player->attacks[index].run(engine, player_entity, enemy);
|
||||
@@ -112,6 +114,21 @@ gc_scene *scene, gc_engine *engine)
|
||||
this->state = ATTACKING;
|
||||
}
|
||||
|
||||
void defend_callback(gc_engine *engine)
|
||||
{
|
||||
struct combat_manager *this = GETSYS(engine, combat_manager);
|
||||
gc_entity *player = NULL;
|
||||
gc_entity *enemy = NULL;
|
||||
|
||||
if (!get_player_and_enemy(engine->scene, &player, &enemy))
|
||||
return;
|
||||
if (GETCMP(enemy, health_component)->dead)
|
||||
combat_end(engine, true);
|
||||
if (this->next_enemy_attack->run)
|
||||
this->next_enemy_attack->run(engine, enemy, player);
|
||||
this->state = ATTACK;
|
||||
}
|
||||
|
||||
void defend(struct combat_manager *this, struct dialog_holder *dialog, \
|
||||
gc_scene *scene, gc_engine *engine)
|
||||
{
|
||||
@@ -119,8 +136,8 @@ gc_scene *scene, gc_engine *engine)
|
||||
gc_entity *enemy = NULL;
|
||||
struct attack_component *enemy_attack;
|
||||
static char str[150];
|
||||
struct attack_holder *attack = NULL;
|
||||
int count;
|
||||
struct dialog_line *line;
|
||||
|
||||
if (!get_player_and_enemy(scene, &player, &enemy))
|
||||
return;
|
||||
@@ -131,10 +148,10 @@ gc_scene *scene, gc_engine *engine)
|
||||
my_printf("No attack found for the enemy.\n");
|
||||
return;
|
||||
}
|
||||
attack = &enemy_attack->attacks[random() % count];
|
||||
snprintf(str, 150, "%s uses attack %s.", "The bee", attack->name);
|
||||
if (attack->run)
|
||||
attack->run(engine, enemy, player);
|
||||
dialog_add_line(dialog, NULL, str, NULL);
|
||||
this->state = ATTACK;
|
||||
this->next_enemy_attack = &enemy_attack->attacks[random() % count];
|
||||
snprintf(str, 150, "%s uses attack %s.", "The bee", \
|
||||
this->next_enemy_attack->name);
|
||||
if ((line = dialog_add_line(dialog, NULL, str, NULL)))
|
||||
line->callback = &defend_callback;
|
||||
this->state = DEFENDING;
|
||||
}
|
||||
@@ -42,27 +42,27 @@ my_strcmp(link->tile->type, "dialog"))
|
||||
}
|
||||
|
||||
bool update_dialog(struct dialog_manager *this, gc_entity *text, \
|
||||
gc_entity *name)
|
||||
gc_entity *name, gc_engine *engine)
|
||||
{
|
||||
struct renderer *rend = GETCMP(name, renderer);
|
||||
struct renderer *name_rend = GETCMP(name, renderer);
|
||||
struct renderer *txt_rend = GETCMP(text, renderer);
|
||||
|
||||
this->current_text = this->current_dialog->text[this->current_line];
|
||||
if (!rend || rend->type != GC_TXTREND || !rend->data)
|
||||
if (!name_rend || name_rend->type != GC_TXTREND || !name_rend->data
|
||||
|| !txt_rend || txt_rend->type != GC_TXTREND || !txt_rend->data)
|
||||
return (true);
|
||||
rend->destroy = &text_safe_destroy;
|
||||
if (this->current_text)
|
||||
((gc_text *)rend->data)->text = this->current_text->name;
|
||||
else
|
||||
((gc_text *)rend->data)->text = NULL;
|
||||
rend = GETCMP(text, renderer);
|
||||
if (!rend || rend->type != GC_TXTREND || !rend->data)
|
||||
return (true);
|
||||
rend->destroy = &text_safe_destroy;
|
||||
name_rend->destroy = &text_safe_destroy;
|
||||
txt_rend->destroy = &text_safe_destroy;
|
||||
if (this->current_text) {
|
||||
((gc_text *) rend->data)->text = this->current_text->text;
|
||||
((gc_text *)name_rend->data)->text = this->current_text->name;
|
||||
((gc_text *)txt_rend->data)->text = this->current_text->text;
|
||||
this->current_input = &this->current_text->inputs[0];
|
||||
} else
|
||||
((gc_text *)rend->data)->text = NULL;
|
||||
if (this->current_text->callback)
|
||||
this->current_text->callback(engine);
|
||||
} else {
|
||||
((gc_text *)txt_rend->data)->text = NULL;
|
||||
((gc_text *)name_rend->data)->text = NULL;
|
||||
}
|
||||
this->current_line++;
|
||||
return (!this->current_text);
|
||||
}
|
||||
@@ -116,8 +116,8 @@ void dialog_next(gc_engine *engine)
|
||||
controllable_set_can_move(scene, false);
|
||||
holder_name = scene->get_entity(scene, 1336);
|
||||
entity = scene->get_entity(scene, 1337);
|
||||
if (!entity || !holder_name ||
|
||||
(!update_dialog(this, entity, holder_name) && handle_input(engine, this)))
|
||||
if (!entity || !holder_name || (!update_dialog(this, entity, \
|
||||
holder_name, engine) && handle_input(engine, this)))
|
||||
return;
|
||||
prefab_destroy(scene, this->dialog_id);
|
||||
this->dialog_id = -1;
|
||||
|
||||
Reference in New Issue
Block a user