combat: rewrite in Zig; add basic damage types and weapon archetypes
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic8055a1cf6bdad1aca13673ea171b4b46a6a6964
This commit is contained in:
parent
7af642612b
commit
22ab6fc6eb
15 changed files with 802 additions and 158 deletions
68
src/items.c
68
src/items.c
|
|
@ -1,8 +1,24 @@
|
|||
#include "common.h"
|
||||
#include "map.h"
|
||||
#include "rng.h"
|
||||
#include "settings.h"
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
DamageClass dmg_class;
|
||||
int base_power;
|
||||
int crit_chance;
|
||||
int crit_multiplier;
|
||||
int status_chance;
|
||||
} WeaponTemplate;
|
||||
|
||||
static const WeaponTemplate weapon_templates[NUM_WEAPON_TEMPLATES] = {
|
||||
{"Dagger", DMG_SLASH, 1, 25, 200, 20}, {"Mace", DMG_IMPACT, 2, 10, 150, 30},
|
||||
{"Spear", DMG_PIERCE, 2, 15, 175, 25}, {"Torch", DMG_FIRE, 1, 5, 150, 40},
|
||||
{"Venom Blade", DMG_POISON, 1, 15, 175, 35},
|
||||
};
|
||||
|
||||
void item_spawn(Item items[], int *count, Map *map, int floor) {
|
||||
*count = 0;
|
||||
|
||||
|
|
@ -33,6 +49,10 @@ void item_spawn(Item items[], int *count, Map *map, int floor) {
|
|||
item.y = iy;
|
||||
item.floor = floor;
|
||||
item.picked_up = 0;
|
||||
item.dmg_class = DMG_SLASH;
|
||||
item.crit_chance = 0;
|
||||
item.crit_multiplier = 100;
|
||||
item.status_chance = 0;
|
||||
|
||||
// Item type distribution
|
||||
int type_roll = rng_int(0, 99);
|
||||
|
|
@ -40,18 +60,24 @@ void item_spawn(Item items[], int *count, Map *map, int floor) {
|
|||
if (type_roll < 50) {
|
||||
// 50% chance for potion
|
||||
item.type = ITEM_POTION;
|
||||
item.power = 5 + rng_int(0, floor * 2); // healing: 5 + 0-2*floor
|
||||
item.power = 5 + rng_int(0, floor * 2);
|
||||
} else if (type_roll < 80) {
|
||||
// 30% chance for weapon
|
||||
// 30% chance for weapon, pick a random template
|
||||
item.type = ITEM_WEAPON;
|
||||
item.power = 1 + rng_int(0, floor); // attack bonus: 1 + 0-floor
|
||||
int tmpl_idx = rng_int(0, NUM_WEAPON_TEMPLATES - 1);
|
||||
const WeaponTemplate *tmpl = &weapon_templates[tmpl_idx];
|
||||
item.power = tmpl->base_power + rng_int(0, floor);
|
||||
item.dmg_class = tmpl->dmg_class;
|
||||
item.crit_chance = tmpl->crit_chance;
|
||||
item.crit_multiplier = tmpl->crit_multiplier;
|
||||
item.status_chance = tmpl->status_chance;
|
||||
} else {
|
||||
// 20% chance for armor
|
||||
item.type = ITEM_ARMOR;
|
||||
item.power = 1 + rng_int(0, floor / 2); // defense bonus
|
||||
item.power = 1 + rng_int(0, floor / 2);
|
||||
}
|
||||
|
||||
items[i] = item;
|
||||
items[*count] = item;
|
||||
(*count)++;
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +91,20 @@ const char *item_get_name(const Item *i) {
|
|||
case ITEM_POTION:
|
||||
return "Potion";
|
||||
case ITEM_WEAPON:
|
||||
return "Weapon";
|
||||
switch (i->dmg_class) {
|
||||
case DMG_SLASH:
|
||||
return "Dagger";
|
||||
case DMG_IMPACT:
|
||||
return "Mace";
|
||||
case DMG_PIERCE:
|
||||
return "Spear";
|
||||
case DMG_FIRE:
|
||||
return "Torch";
|
||||
case DMG_POISON:
|
||||
return "Venom Blade";
|
||||
default:
|
||||
return "Weapon";
|
||||
}
|
||||
case ITEM_ARMOR:
|
||||
return "Armor";
|
||||
default:
|
||||
|
|
@ -124,3 +163,20 @@ void item_use(Player *p, Item *i) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char *dmg_class_get_short(DamageClass dc) {
|
||||
switch (dc) {
|
||||
case DMG_SLASH:
|
||||
return "SLA";
|
||||
case DMG_IMPACT:
|
||||
return "IMP";
|
||||
case DMG_PIERCE:
|
||||
return "PRC";
|
||||
case DMG_FIRE:
|
||||
return "FIR";
|
||||
case DMG_POISON:
|
||||
return "PSN";
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue