2017-02-27 15:27:48 +01:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2017-02-27 15:27:48 +01:00
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* 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>.
|
2017-02-27 15:27:48 +01:00
|
|
|
*/
|
|
|
|
|
2017-11-25 20:45:11 +01:00
|
|
|
#include "taisei.h"
|
|
|
|
|
2017-02-27 15:27:48 +01:00
|
|
|
#include "difficulty.h"
|
2017-03-11 04:41:57 +01:00
|
|
|
#include "resource/resource.h"
|
2019-07-25 02:31:02 +02:00
|
|
|
#include "global.h"
|
2017-02-27 15:27:48 +01:00
|
|
|
|
2018-07-23 19:07:59 +02:00
|
|
|
typedef struct DiffDef {
|
|
|
|
const char *name;
|
|
|
|
const char *spr_name;
|
|
|
|
Color color;
|
|
|
|
} DiffDef;
|
|
|
|
|
|
|
|
static DiffDef diffs[] = {
|
|
|
|
{ "Easy", "difficulty/easy", { 0.5, 1.0, 0.5, 1.0 } },
|
|
|
|
{ "Normal", "difficulty/normal", { 0.5, 0.5, 1.0, 1.0 } },
|
|
|
|
{ "Hard", "difficulty/hard", { 1.0, 0.5, 0.5, 1.0 } },
|
|
|
|
{ "Lunatic", "difficulty/lunatic", { 1.0, 0.5, 1.0, 1.0 } },
|
|
|
|
|
|
|
|
// TODO: sprite for this
|
|
|
|
{ "Extra", "difficulty/lunatic", { 0.5, 1.0, 1.0, 1.0 } },
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline DiffDef* get_diff_def(Difficulty diff) {
|
|
|
|
uint idx = diff - D_Easy;
|
|
|
|
|
|
|
|
if(idx < sizeof(diffs)/sizeof(*diffs)) {
|
|
|
|
return diffs + idx;
|
2018-01-12 19:26:07 +01:00
|
|
|
}
|
2018-07-23 19:07:59 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* difficulty_name(Difficulty diff) {
|
|
|
|
DiffDef *d = get_diff_def(diff);
|
|
|
|
return d ? d->name : "Unknown";
|
2017-02-27 15:27:48 +01:00
|
|
|
}
|
|
|
|
|
2018-02-06 07:19:25 +01:00
|
|
|
const char* difficulty_sprite_name(Difficulty diff) {
|
2018-07-23 19:07:59 +02:00
|
|
|
DiffDef *d = get_diff_def(diff);
|
|
|
|
return d ? d->spr_name : "difficulty/unknown";
|
2017-03-10 16:26:10 +01:00
|
|
|
}
|
|
|
|
|
2018-07-23 19:07:59 +02:00
|
|
|
const Color* difficulty_color(Difficulty diff) {
|
|
|
|
static Color unknown_clr = { 0.5, 0.5, 0.5, 1.0 };
|
|
|
|
DiffDef *d = get_diff_def(diff);
|
|
|
|
return d ? &d->color : &unknown_clr;
|
2017-02-27 15:27:48 +01:00
|
|
|
}
|
2017-03-11 04:41:57 +01:00
|
|
|
|
|
|
|
void difficulty_preload(void) {
|
2018-01-12 19:26:07 +01:00
|
|
|
for(Difficulty diff = D_Easy; diff < NUM_SELECTABLE_DIFFICULTIES + D_Easy; ++diff) {
|
2018-02-06 07:19:25 +01:00
|
|
|
preload_resource(RES_SPRITE, difficulty_sprite_name(diff), RESF_PERMANENT);
|
2018-01-12 19:26:07 +01:00
|
|
|
}
|
2017-03-11 04:41:57 +01:00
|
|
|
}
|
2019-07-25 02:31:02 +02:00
|
|
|
|
|
|
|
double difficulty_value(double easy, double normal, double hard, double lunatic) {
|
|
|
|
uint idx = global.diff - D_Easy;
|
|
|
|
double vals[NUM_SELECTABLE_DIFFICULTIES] = { easy, normal, hard, lunatic };
|
|
|
|
assert(idx < ARRAY_SIZE(vals));
|
|
|
|
return vals[idx];
|
|
|
|
}
|