summaryrefslogtreecommitdiff
path: root/kon/konparty.h
diff options
context:
space:
mode:
Diffstat (limited to 'kon/konparty.h')
-rw-r--r--kon/konparty.h141
1 files changed, 141 insertions, 0 deletions
diff --git a/kon/konparty.h b/kon/konparty.h
new file mode 100644
index 0000000..99b6829
--- /dev/null
+++ b/kon/konparty.h
@@ -0,0 +1,141 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * konparty.h
+ *
+ * Copyright (c) 2026 KonAki
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef KONPARTY_H
+#define KONPARTY_H
+
+#include "konbattle.h"
+
+/*** definition ***/
+
+/* the people in a role playing game and what they carry: classes with stats by level, levelling up, equipment, the
+party, gold and the bag. fights are konbattle, this builds the battlers for it and takes the results back.
+all the tables are yours and are only read, the changing parts (actors, how many of each item) are yours too */
+
+#define KON_EQUIP_SLOTS 5 /* weapon, shield, head, body, accessory by default, the names are yours */
+#define KON_ACTOR_SKILLS 64
+#define KON_CLASS_LEARNINGS 32
+#define KON_PARTY_MAX 8
+#define KON_ITEM_MAX 99
+#define KON_GOLD_MAX 99999999
+
+typedef enum { KON_ITEM_ITEM, KON_ITEM_KEY, KON_ITEM_WEAPON, KON_ITEM_ARMOR } kon_itemKind_t;
+
+/* where an item can be used: 0 anywhere, 1 in a fight only, 2 in the menu only, 3 never */
+typedef struct kon_item {
+ const char *name;
+ kon_itemKind_t kind;
+ int price; /* 0 is not for sale */
+ int consumable;
+ int occasion;
+ int slot; /* for weapons and armour, which of the equipment slots */
+ int plus[KON_PARAMS];
+ int skill; /* what using it does, a number in the skills table, -1 for nothing */
+} kon_item_t;
+
+typedef struct kon_class {
+ const char *name;
+ int maxLevel;
+ const short *params[KON_PARAMS]; /* each as long as maxLevel + 1, the number for level 5 is params[i][5] */
+ int expBasis, expExtra, expAccA, expAccB; /* the usual curve numbers, 30 20 30 30 for the common one */
+ struct { int level; int skill; } learn[KON_CLASS_LEARNINGS];
+ int learnCount;
+} kon_class_t;
+
+typedef struct kon_database {
+ const kon_item_t *items;
+ int itemCount;
+ const kon_class_t *classes;
+ int classCount;
+ const kon_skill_t *skills;
+ int skillCount;
+ const kon_state_t *states;
+ int stateCount;
+} kon_database_t;
+
+typedef struct kon_actor {
+ kon_battler_t b; /* the numbers as the fight uses them. hp, mp, tp and states stay here between fights */
+ int classId;
+ int exp;
+ int equip[KON_EQUIP_SLOTS]; /* an item number or -1 */
+ int skills[KON_ACTOR_SKILLS];
+ int skillCount;
+} kon_actor_t;
+
+typedef struct kon_party {
+ const kon_database_t *db;
+ kon_actor_t *actors;
+ int actorCount;
+ int *itemCounts; /* one for each item in the database */
+ int32_t *vars; /* for formulas, can be the script's */
+ int varCount;
+ int members[KON_PARTY_MAX]; /* actor numbers, the first is the leader */
+ int memberCount;
+ int battleMax; /* how many of them fight at once */
+ int gold;
+ long steps;
+ double playTime;
+} kon_party_t;
+
+/*** actors ***/
+
+void kon_partyInit(kon_party_t *p, const kon_database_t *db, kon_actor_t *actors, int actorCount, int *itemCounts);
+
+/* a new person at a level, with full hp and mp and what their class knows by then */
+int kon_actorInit(kon_party_t *p, int actor, const char *name, int classId, int level);
+
+/* stats follow class, level and equipment. call after changing any of them (the functions below do) */
+void kon_actorRefresh(const kon_party_t *p, int actor);
+int kon_classExp(const kon_class_t *c, int level);
+int kon_actorLearn(kon_party_t *p, int actor, int skill);
+
+/* returns levels gained, skills learned from them are written to learned */
+int kon_actorGainExp(kon_party_t *p, int actor, int exp, int *learned, int cap);
+
+/* an item number to wear, -1 to take it off. the bag gives and takes the items. 0 if it cannot be done */
+int kon_actorEquip(kon_party_t *p, int actor, int slot, int item);
+
+/*** party ***/
+
+int kon_partyAdd(kon_party_t *p, int actor);
+int kon_partyRemove(kon_party_t *p, int actor);
+int kon_partySwap(kon_party_t *p, int a, int b);
+
+/* the bag */
+int kon_bagCount(const kon_party_t *p, int item);
+int kon_bagAdd(kon_party_t *p, int item, int count); /* returns how many fitted */
+int kon_bagRemove(kon_party_t *p, int item, int count); /* returns how many were there to take */
+int kon_partyBuy(kon_party_t *p, int item, int count);
+int kon_partySell(kon_party_t *p, int item, int count);
+void kon_partyGold(kon_party_t *p, int amount);
+
+/* for a fight: the members that fight, copied into battlers, and the same back afterwards. both return how many */
+int kon_partyBattlers(const kon_party_t *p, kon_battler_t *out, int cap);
+void kon_partyApply(kon_party_t *p, const kon_battler_t *in, int count);
+
+/* use an item from the menu on a member, like a potion. -1 if it cannot be used right now, otherwise what kon_battleUse says */
+int kon_partyUseItem(kon_party_t *p, int item, int user, int target, kon_result_t *out, int cap);
+
+#endif /* KONPARTY_H */