taisei/src/plrmodes.c

199 lines
4.8 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
2019-07-03 20:00:56 +02:00
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
*/
#include "taisei.h"
#include "player.h"
#include "global.h"
2011-11-02 20:00:14 +01:00
#include "stage.h"
#include "plrmodes.h"
#include "plrmodes/marisa.h"
#include "plrmodes/youmu.h"
Add Reimu Hakurei as a playable character (#106) * Reimu (#101) * add the reimu * Add Reimu story * account for various blunders * add reimu dialog picture * Reimu: WIP yin-yang orbs * reimu: fix up indents * Reimu: swap the shotmode names to match the kanji order in her Japanese name * Reimu: compatibility with the latest system * WIP ReimuA crap * ReimuA homing trails * more ReimuA stuff * more ReimuA adjustments + enhanced DPS stats * Reimu: stubs for new player animation sequences * Reimu: occupy the 0th character slot * Reimu: tweak needle sprite * Reimu: buff movement speed to better match Touhou * Reimu: fixup for the recent projectile changes * ReimuA: make homing shots a bit smaller; give them custom effect on collision * Reimu: add intermediate frames; move some loose sprites to the atlas * Reimu: fix compile errors * replace DBL_MAX by INFINITY * Don’t draw reimu orbs twice fixes #127 * add new reimu dialog pic * ReimuA adjustments (mostly homing); it's still OP * wip ReimuB gaps * still not sure where i'm going with these gaps * meh * Reimu: premultiplied alpha fixups after rebase * reimuB shot pattern with basic power scaling (not balanced at all) * reimuB: some lame-ass particle effects * ReimuB bomb effect prototype * reimuA bomb prototype * fix reimu shots for the new damage system * Reimu: use the new player_is_bomb_active() function, add placeholder BG for ReimuB * some reimuB bomb projectiles * ReimuB bomb bg and some framebuffer utils required to support it. Might reuse this at least in part for ReimuA unless we come up with something better. * hack to fix ReimuB bomb fade; refactoring needed * reimuA damaging bombs * fix ub * prevent nan when reimuA bombs without enemies present * add a bomb_bg to reimuA * ... * various fantasy seal tweaks * Reimu: placeholder bomb sounds; slight fantasy seal buff * fix null pointer dereference * Reimu "balance" adjustments; minor fixes * putting bandaids over gunshot wounds * Add aoe damage and bullet cancel to ReimuB's bomb * more exorcism porn * make reimu bomb bg runes better visible on dark backgrounds * More ReimuA shot changes
2018-08-11 21:13:48 +02:00
#include "plrmodes/reimu.h"
static PlayerCharacter *player_characters[] = {
Add Reimu Hakurei as a playable character (#106) * Reimu (#101) * add the reimu * Add Reimu story * account for various blunders * add reimu dialog picture * Reimu: WIP yin-yang orbs * reimu: fix up indents * Reimu: swap the shotmode names to match the kanji order in her Japanese name * Reimu: compatibility with the latest system * WIP ReimuA crap * ReimuA homing trails * more ReimuA stuff * more ReimuA adjustments + enhanced DPS stats * Reimu: stubs for new player animation sequences * Reimu: occupy the 0th character slot * Reimu: tweak needle sprite * Reimu: buff movement speed to better match Touhou * Reimu: fixup for the recent projectile changes * ReimuA: make homing shots a bit smaller; give them custom effect on collision * Reimu: add intermediate frames; move some loose sprites to the atlas * Reimu: fix compile errors * replace DBL_MAX by INFINITY * Don’t draw reimu orbs twice fixes #127 * add new reimu dialog pic * ReimuA adjustments (mostly homing); it's still OP * wip ReimuB gaps * still not sure where i'm going with these gaps * meh * Reimu: premultiplied alpha fixups after rebase * reimuB shot pattern with basic power scaling (not balanced at all) * reimuB: some lame-ass particle effects * ReimuB bomb effect prototype * reimuA bomb prototype * fix reimu shots for the new damage system * Reimu: use the new player_is_bomb_active() function, add placeholder BG for ReimuB * some reimuB bomb projectiles * ReimuB bomb bg and some framebuffer utils required to support it. Might reuse this at least in part for ReimuA unless we come up with something better. * hack to fix ReimuB bomb fade; refactoring needed * reimuA damaging bombs * fix ub * prevent nan when reimuA bombs without enemies present * add a bomb_bg to reimuA * ... * various fantasy seal tweaks * Reimu: placeholder bomb sounds; slight fantasy seal buff * fix null pointer dereference * Reimu "balance" adjustments; minor fixes * putting bandaids over gunshot wounds * Add aoe damage and bullet cancel to ReimuB's bomb * more exorcism porn * make reimu bomb bg runes better visible on dark backgrounds * More ReimuA shot changes
2018-08-11 21:13:48 +02:00
&character_reimu,
&character_marisa,
&character_youmu,
};
static PlayerMode *player_modes[] = {
Add Reimu Hakurei as a playable character (#106) * Reimu (#101) * add the reimu * Add Reimu story * account for various blunders * add reimu dialog picture * Reimu: WIP yin-yang orbs * reimu: fix up indents * Reimu: swap the shotmode names to match the kanji order in her Japanese name * Reimu: compatibility with the latest system * WIP ReimuA crap * ReimuA homing trails * more ReimuA stuff * more ReimuA adjustments + enhanced DPS stats * Reimu: stubs for new player animation sequences * Reimu: occupy the 0th character slot * Reimu: tweak needle sprite * Reimu: buff movement speed to better match Touhou * Reimu: fixup for the recent projectile changes * ReimuA: make homing shots a bit smaller; give them custom effect on collision * Reimu: add intermediate frames; move some loose sprites to the atlas * Reimu: fix compile errors * replace DBL_MAX by INFINITY * Don’t draw reimu orbs twice fixes #127 * add new reimu dialog pic * ReimuA adjustments (mostly homing); it's still OP * wip ReimuB gaps * still not sure where i'm going with these gaps * meh * Reimu: premultiplied alpha fixups after rebase * reimuB shot pattern with basic power scaling (not balanced at all) * reimuB: some lame-ass particle effects * ReimuB bomb effect prototype * reimuA bomb prototype * fix reimu shots for the new damage system * Reimu: use the new player_is_bomb_active() function, add placeholder BG for ReimuB * some reimuB bomb projectiles * ReimuB bomb bg and some framebuffer utils required to support it. Might reuse this at least in part for ReimuA unless we come up with something better. * hack to fix ReimuB bomb fade; refactoring needed * reimuA damaging bombs * fix ub * prevent nan when reimuA bombs without enemies present * add a bomb_bg to reimuA * ... * various fantasy seal tweaks * Reimu: placeholder bomb sounds; slight fantasy seal buff * fix null pointer dereference * Reimu "balance" adjustments; minor fixes * putting bandaids over gunshot wounds * Add aoe damage and bullet cancel to ReimuB's bomb * more exorcism porn * make reimu bomb bg runes better visible on dark backgrounds * More ReimuA shot changes
2018-08-11 21:13:48 +02:00
&plrmode_reimu_a,
&plrmode_reimu_b,
&plrmode_marisa_a,
&plrmode_marisa_b,
&plrmode_youmu_a,
&plrmode_youmu_b,
};
PlayerCharacter* plrchar_get(CharacterID id) {
assert((unsigned)id < NUM_CHARACTERS);
PlayerCharacter *pc = player_characters[id];
assert(pc->id == id);
return pc;
2011-07-05 15:20:19 +02:00
}
void plrchar_preload(PlayerCharacter *pc) {
preload_resource(RES_ANIM, pc->player_sprite_name, RESF_DEFAULT);
preload_resource(RES_SPRITE, pc->dialog_base_sprite_name, RESF_DEFAULT);
for(int i = 0; i < DIALOG_NUM_FACES; ++i) {
preload_resource(RES_SPRITE, pc->dialog_face_sprite_names[i], RESF_DEFAULT);
}
}
void plrchar_make_bomb_portrait(PlayerCharacter *pc, Sprite *out_spr) {
r_state_push();
Sprite *s_base = get_sprite(pc->dialog_base_sprite_name);
Sprite *s_face = get_sprite(pc->dialog_face_sprite_names[DIALOG_FACE_NORMAL]);
uint tex_w = s_base->tex_area.extent.w;
uint tex_h = s_base->tex_area.extent.h;
uint spr_w = s_base->extent.w;
uint spr_h = s_base->extent.h;
Texture *ptex = r_texture_create(&(TextureParams) {
.type = TEX_TYPE_RGBA_8,
.width = tex_w,
.height = tex_h,
.filter.min = TEX_FILTER_LINEAR_MIPMAP_LINEAR,
.filter.mag = TEX_FILTER_LINEAR,
.mipmap_mode = TEX_MIPMAP_AUTO,
.mipmaps = 3,
});
char label[128];
snprintf(label, sizeof(label), "%s bomb portrait", pc->lower_name);
r_texture_set_debug_label(ptex, label);
Framebuffer *fb = r_framebuffer_create();
snprintf(label, sizeof(label), "%s bomb portrait FB", pc->lower_name);
r_framebuffer_set_debug_label(fb, label);
r_framebuffer_attach(fb, ptex, 0, FRAMEBUFFER_ATTACH_COLOR0);
r_framebuffer_viewport(fb, 0, 0, tex_w, tex_h);
r_framebuffer(fb);
r_mat_mode(MM_PROJECTION);
r_mat_push();
r_mat_ortho(0, spr_w, spr_h, 0, -1, 1);
r_mat_mode(MM_MODELVIEW);
r_mat_push();
r_mat_identity();
SpriteParams sp = { 0 };
sp.sprite_ptr = s_base;
sp.blend = BLEND_NONE;
sp.pos.x = spr_w / 2.0 - s_base->offset.x;
sp.pos.y = spr_h / 2.0 - s_base->offset.y;
sp.color = RGBA(1, 1, 1, 1);
sp.shader_ptr = r_shader_get("sprite_default"),
r_draw_sprite(&sp);
sp.blend = BLEND_PREMUL_ALPHA;
sp.sprite_ptr = s_face;
r_draw_sprite(&sp);
r_flush_sprites();
r_mat_pop();
r_mat_mode(MM_PROJECTION);
r_mat_pop();
r_state_pop();
r_framebuffer_destroy(fb);
Sprite s = { 0 };
s.tex = ptex;
s.offset = s_base->offset;
s.extent = s_base->extent;
s.tex_area.w = tex_w;
s.tex_area.h = tex_h;
*out_spr = s;
}
void plrchar_make_dialog_actor(PlayerCharacter *pc, DialogActor *out_actor) {
out_actor->base = get_sprite(pc->dialog_base_sprite_name);
for(int i = 0; i < DIALOG_NUM_FACES; ++i) {
out_actor->faces[i] = get_sprite(pc->dialog_face_sprite_names[i]);
}
out_actor->face = out_actor->faces[DIALOG_FACE_NORMAL];
}
int plrmode_repr(char *out, size_t outsize, PlayerMode *mode, bool internal) {
assert(mode->character != NULL);
assert((unsigned)mode->shot_mode < NUM_SHOT_MODES_PER_CHARACTER);
return snprintf(out, outsize, "%s%c",
internal ? mode->character->lower_name : mode->character->proper_name,
mode->shot_mode + 'A'
);
}
PlayerMode* plrmode_find(CharacterID char_id, ShotModeID shot_id) {
for(int i = 0; i < NUM_PLAYER_MODES; ++i) {
PlayerMode *mode = player_modes[i];
if(mode->character->id == char_id && mode->shot_mode == shot_id) {
return mode;
}
2017-03-30 17:11:21 +02:00
}
return NULL;
2011-11-01 21:20:40 +01:00
}
PlayerMode* plrmode_parse(const char *name) {
CharacterID char_id = (CharacterID)-1;
ShotModeID shot_id = (ShotModeID)-1;
char buf[strlen(name) + 1];
strcpy(buf, name);
2011-11-01 21:20:40 +01:00
for(int i = 0; i < sizeof(buf); ++i) {
buf[i] = tolower(buf[i]);
}
if(!*buf) {
log_debug("Got an empty string");
return NULL;
}
2011-07-05 15:20:19 +02:00
char shot = buf[sizeof(buf) - 2];
if(shot < 'a' || shot >= 'a' + NUM_SHOT_MODES_PER_CHARACTER) {
log_debug("Got invalid shotmode: %c", shot);
return NULL;
}
shot_id = shot - 'a';
buf[sizeof(buf) - 2] = 0;
for(int i = 0; i < NUM_CHARACTERS; ++i) {
PlayerCharacter *chr = player_characters[i];
if(!strcmp(buf, chr->lower_name)) {
char_id = chr->id;
2011-07-05 15:20:19 +02:00
}
}
if(char_id == (CharacterID)-1) {
log_debug("Got invalid character: %s", buf);
return NULL;
}
return plrmode_find(char_id, shot_id);
2017-04-02 10:16:52 +02:00
}
void plrmode_preload(PlayerMode *mode) {
assert(mode != NULL);
plrchar_preload(mode->character);
if(mode->procs.preload) {
mode->procs.preload();
}
}