1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/* 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"
#include "konsave.h"
#ifdef __cplusplus
extern "C" {
#endif
/*** 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_ACTOR_NAME 32
#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 */
char name[KON_ACTOR_NAME]; /* b.name points at this, so copy an actor with kon_actorRename after */
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);
void kon_actorRename(kon_party_t *p, int actor, const char *name);
/* 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);
/*** saving ***/
/* the party, the actors and the bag as the PRTY and BAGS chunks. what is saved is what changes: levels, hp, equipment,
skills, who is in the party, gold. the tables come from the game, so a new version of a game can still read old saves.
if a load returns 0 the party may be half changed, start again or load a different save */
void kon_partySave(const kon_party_t *p, kon_saveWriter_t *w);
int kon_partyLoad(kon_party_t *p, const kon_saveReader_t *r);
#ifdef __cplusplus
}
#endif
#endif /* KONPARTY_H */
|