Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cmake-build-debug/*
build/
.build
__pycache__
.venv
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ add_compile_options(-Werror -Wno-format-overflow -Wno-format-truncation -Wno-wri
# Load Third Party libraries.
include(cmake/CPM.cmake)

CPMAddPackage("gh:fmtlib/fmt#9.1.0")
CPMAddPackage("gh:nlohmann/json@3.11.2")
CPMAddPackage("gh:fmtlib/fmt#11.1.3")
CPMAddPackage("gh:nlohmann/json@3.11.3")
# CPMAddPackage("gh:catchorg/Catch2@3.2.1")
# CPMAddPackage("gh:OlivierLDff/asio.cmake#asio-1-24-0")

Expand Down
3 changes: 2 additions & 1 deletion include/casting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define MAG_BULK_OBJS (1 << 12)
#define MAG_REPEAT (1 << 13)
#define NUM_ROUTINE_TYPES 13
typedef std::bitset<NUM_ROUTINE_TYPES> RoutineFlags;

#define TYPE_UNDEFINED -1

Expand Down Expand Up @@ -145,7 +146,7 @@ void char_forget_casters(CharData *ch);
#define CASTING(ch) (EVENT_FLAGGED(ch, EVENT_CASTING))

#define STOP_CASTING(ch) \
REMOVE_FLAG(GET_EVENT_FLAGS(ch), EVENT_CASTING); \
GET_EVENT_FLAGS(ch).reset(EVENT_CASTING); \
if ((ch)->casting.obj) \
obj_forget_caster((ch)->casting.obj, ch); \
if ((ch)->casting.tch) \
Expand Down
5 changes: 3 additions & 2 deletions include/clan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define CPRIV_ALTS 13
#define CPRIV_CHAT 14
#define NUM_CLAN_PRIVS 15 /* Number of clan privileges */
typedef std::bitset<NUM_CLAN_PRIVS> ClanPrivilegeSet;

#define MIN_CLAN_RANKS 2
#define MAX_CLAN_RANKS 100
Expand Down Expand Up @@ -77,7 +78,7 @@
struct ClanMembership;
struct ClanRank {
char *title;
flagvector privileges[FLAGVECTOR_SIZE(NUM_CLAN_PRIVS)];
ClanPrivilegeSet privileges;
};

struct Clan {
Expand Down Expand Up @@ -163,7 +164,7 @@ const struct {
#define GET_CLAN_RANK(ch) (GET_CLAN_MEMBERSHIP(ch) ? GET_CLAN_MEMBERSHIP(ch)->rank : RANK_NONE)
#define GET_CLAN_TITLE(ch) (IS_CLAN_MEMBER(ch) ? GET_CLAN(ch)->ranks[GET_CLAN_RANK(ch) - 1].title : NULL)
#define MEMBER_CAN(member, priv) \
(IS_MEMBER_RANK(member->rank) && IS_FLAGGED(member->clan->ranks[member->rank - 1].privileges, (priv)))
(IS_MEMBER_RANK(member->rank) && member->clan->ranks[member->rank - 1].privileges.test((priv)))
#define HAS_CLAN_PRIV(ch, priv) (GET_CLAN_MEMBERSHIP(ch) ? MEMBER_CAN(GET_CLAN_MEMBERSHIP(ch), (priv)) : false)
#define CAN_DO_PRIV(ch, priv) (IS_CLAN_ADMIN(ch) || IS_CLAN_SUPERADMIN(ch) || HAS_CLAN_PRIV((ch), (priv)))
#define GET_CLAN_SNOOP(ch) ((ch)->player_specials->clan_snoop)
Expand Down
6 changes: 4 additions & 2 deletions include/class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "structs.hpp"
#include "sysdep.hpp"

#include <bitset>

#define CLASS_UNDEFINED -1
#define CLASS_SORCERER 0
#define CLASS_CLERIC 1
Expand Down Expand Up @@ -98,8 +100,9 @@ struct ClassDef {
*/

/* List of permanent effect flags */
flagvector effect_flags[FLAGVECTOR_SIZE(NUM_EFF_FLAGS)];
EffectFlags effect_flags;
};
;
extern ClassDef classes[NUM_CLASSES];

#define VALID_CLASSNUM(num) (num < NUM_CLASSES)
Expand Down Expand Up @@ -145,7 +148,6 @@ extern ClassDef classes[NUM_CLASSES];
? classes[(int)GET_CLASS(ch)].nowear_flag && OBJ_FLAGGED(obj, classes[(int)GET_CLASS(ch)].nowear_flag) \
: 0)


enum level_action { LEVEL_GAIN, LEVEL_LOSE };

void init_classes(void);
Expand Down
2 changes: 1 addition & 1 deletion include/db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct PlayerIndexElement {
char *name;
long id;
int level;
int flags;
std::bitset<64> flags;
time_t last;
};

Expand Down
62 changes: 61 additions & 1 deletion include/defines.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <bitset>
#include <unordered_map>

// Do not include files here, this is a header file for the defines only.

#define NOWHERE -1 /* nil reference for room-database */
Expand Down Expand Up @@ -73,6 +76,7 @@
#define PRV_ANON_TOGGLE 2 /* can toggle anon */
#define PRV_AUTO_GAIN 3 /* don't need to level gain */
#define NUM_PRV_FLAGS 4
typedef std::bitset<NUM_PRV_FLAGS> PrivilegeFlags;

/* Mobile flags: used by CharData.char_specials.act */
#define MOB_SPEC 0 /* Mob has a callable spec-proc */
Expand Down Expand Up @@ -118,6 +122,13 @@
#define MOB_MEDITATE 40
#define NUM_MOB_FLAGS 41 /* Update this when you add a flag! */

#if NUM_MOB_FLAGS > NUM_PLR_FLAGS
#define MAX_MOB_PLR_FLAGS NUM_MOB_FLAGS
#else
#define MAX_MOB_PLR_FLAGS NUM_PLR_FLAGS
#endif
typedef std::bitset<MAX_MOB_PLR_FLAGS> PlayerOrMobFlags;

/* Some mount stuff */
#define MAX_MOUNT_LEVEL 27 /* The maximum level of mountable mobs */

Expand Down Expand Up @@ -496,6 +507,7 @@
#define EFF_SHOCK_WEAPON 88
#define EFF_RADIANT_WEAPON 89
#define NUM_EFF_FLAGS 90 /* Keep me updated */
typedef std::bitset<NUM_EFF_FLAGS> EffectFlags;

/* Preference flags: used by CharData.player_specials.pref */
#define PRF_BRIEF 0 /* Room descs won't normally be shown */
Expand Down Expand Up @@ -536,6 +548,7 @@
#define PRF_SACRIFICIAL 35 /* Sacrificial spells autotarget self */
#define PRF_PETASSIST 36 /* Should your pet assist you as you fight */
#define NUM_PRF_FLAGS 37
typedef std::bitset<NUM_PRF_FLAGS> PreferenceFlags;

#define CIRCLE_1 1
#define CIRCLE_2 9
Expand Down Expand Up @@ -1156,8 +1169,9 @@
#define ITEM_ANTI_COLOSSAL 49
#define ITEM_ANTI_TITANIC 50
#define ITEM_ANTI_MOUNTAINOUS 51
#define ITEM_ANTI_ARBOREAN 52 /* Not usable by Arboreans */
#define ITEM_ANTI_ARBOREAN 52 /* Not usable by Arboreans */
#define NUM_ITEM_FLAGS 53
typedef std::bitset<NUM_ITEM_FLAGS> ExtraObjectFlags;

/* Modifier constants used with obj effects ('A' fields) */
#define APPLY_NONE 0 /* No effect */
Expand Down Expand Up @@ -1333,3 +1347,49 @@
#define MAX_OBJ_APPLIES 6

#define MEDITATE_BONUS 10

#define EVENT_AUTODOUSE 1
#define EVENT_CAMP 2
#define EVENT_HURT 3
#define EVENT_MOB_QUIT 4
#define EVENT_NAME_TIMEOUT 5
#define EVENT_RECALL 6
#define EVENT_ROOM_UNDO 7
#define EVENT_SPELL 8
#define EVENT_TRACK 9
#define EVENT_TRIGGER_WAIT 10
#define EVENT_SINK_AND_LOSE 11
#define EVENT_BATTLE_PARALYSIS 12
#define EVENT_CASTING 13
#define EVENT_REGEN_HP 14
#define EVENT_REGEN_SPELLSLOT 15
#define EVENT_REGEN_MOVE 16
// #define EVENT_REGEN_MANA 17
#define EVENT_SCRIBE 18
#define EVENT_QUICK_AGGRO 19
#define EVENT_DIE 20
#define EVENT_RAGE 21
#define EVENT_EXTRACT 22 /* To extract a char, for whatever reason */
#define EVENT_GRAVITY 23
#define EVENT_COOLDOWN 24
#define EVENT_FULLPURGE 25
#define EVENT_OVERWEIGHT 26
#define EVENT_FALLTOGROUND 27
#define EVENT_COMMAND 28
#define EVENT_EDITOR_START 29
#define EVENT_GET_MONEY 30
/* Update MAX_EVENT to be last event value + 1, please */
#define MAX_EVENT 31
typedef std::bitset<MAX_EVENT> EventFlags;

typedef std::unordered_map<int, bool> CommandCache;

/* The EX_xxxx constants are used in exit_info. */
#define EX_ISDOOR 0 /* Exit is a door */
#define EX_CLOSED 1 /* The door is closed */
#define EX_LOCKED 2 /* The door is locked */
#define EX_PICKPROOF 3 /* Lock can't be picked */
#define EX_HIDDEN 4 /* exit is hidden */
#define EX_DESCRIPT 5 /* Just an extra description */
#define MAX_EXIT_INFO_FLAGS 6
typedef std::bitset<MAX_EXIT_INFO_FLAGS> ExitInfoFlags;
33 changes: 0 additions & 33 deletions include/events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,6 @@ void cancel_event_list(Event **list);
GenericEventData *mkgenericevent(CharData *ch, CharData *vict, ObjData *obj);
void delayed_command(CharData *ch, char *command, int delay, bool repeatable);

#define EVENT_AUTODOUSE 1
#define EVENT_CAMP 2
#define EVENT_HURT 3
#define EVENT_MOB_QUIT 4
#define EVENT_NAME_TIMEOUT 5
#define EVENT_RECALL 6
#define EVENT_ROOM_UNDO 7
#define EVENT_SPELL 8
#define EVENT_TRACK 9
#define EVENT_TRIGGER_WAIT 10
#define EVENT_SINK_AND_LOSE 11
#define EVENT_BATTLE_PARALYSIS 12
#define EVENT_CASTING 13
#define EVENT_REGEN_HP 14
#define EVENT_REGEN_SPELLSLOT 15
#define EVENT_REGEN_MOVE 16
// #define EVENT_REGEN_MANA 17
#define EVENT_SCRIBE 18
#define EVENT_QUICK_AGGRO 19
#define EVENT_DIE 20
#define EVENT_RAGE 21
#define EVENT_EXTRACT 22 /* To extract a char, for whatever reason */
#define EVENT_GRAVITY 23
#define EVENT_COOLDOWN 24
#define EVENT_FULLPURGE 25
#define EVENT_OVERWEIGHT 26
#define EVENT_FALLTOGROUND 27
#define EVENT_COMMAND 28
#define EVENT_EDITOR_START 29
#define EVENT_GET_MONEY 30
/* Update MAX_EVENT to be last event value + 1, please */
#define MAX_EVENT 31

EVENTFUNC(extract_event);
EVENTFUNC(hurt_event);
EVENTFUNC(fullpurge_event);
Expand Down
24 changes: 8 additions & 16 deletions include/exits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,24 @@
#include "structs.hpp"
#include "sysdep.hpp"

/* The EX_xxxx constants are used in exit_info. */
#define EX_ISDOOR (1 << 0) /* Exit is a door */
#define EX_CLOSED (1 << 1) /* The door is closed */
#define EX_LOCKED (1 << 2) /* The door is locked */
#define EX_PICKPROOF (1 << 3) /* Lock can't be picked */
#define EX_HIDDEN (1 << 4) /* exit is hidden */
#define EX_DESCRIPT (1 << 5) /* Just an extra description */

struct Exit {
char *general_description; /* When look DIR. */
char *keyword; /* for open/close */
int exit_info; /* Exit info */
ExitInfoFlags exit_info; /* Exit info */
obj_num key; /* Key's vnum (-1 for no key) */
room_num to_room; /* Where it leads (real number) */
};

extern const char *cmd_door[];

#define EXIT_IS_DOOR(e) ((e)->exit_info & EX_ISDOOR)
#define EXIT_IS_CLOSED(e) ((e)->exit_info & EX_CLOSED)
#define EXIT_IS_OPEN(e) (!EXIT_IS_DOOR(e) || !((e)->exit_info & EX_CLOSED))
#define EXIT_IS_LOCKED(e) ((e)->exit_info & EX_LOCKED)
#define EXIT_IS_DOOR(e) ((e)->exit_info.test(EX_ISDOOR))
#define EXIT_IS_CLOSED(e) ((e)->exit_info.test(EX_CLOSED))
#define EXIT_IS_OPEN(e) (!EXIT_IS_DOOR(e) || !((e)->exit_info.test(EX_CLOSED)))
#define EXIT_IS_LOCKED(e) ((e)->exit_info.test(EX_LOCKED))
#define EXIT_DOES_LOCK(e) ((e)->key != -1)
#define EXIT_IS_PICKPROOF(e) ((e)->exit_info & EX_PICKPROOF)
#define EXIT_IS_HIDDEN(e) ((e)->exit_info & EX_HIDDEN)
#define EXIT_IS_DESCRIPTION(e) ((e)->exit_info & EX_DESCRIPT)
#define EXIT_IS_PICKPROOF(e) ((e)->exit_info.test(EX_PICKPROOF))
#define EXIT_IS_HIDDEN(e) ((e)->exit_info.test(EX_HIDDEN))
#define EXIT_IS_DESCRIPTION(e) ((e)->exit_info.test(EX_DESCRIPT))

#define EXIT_NDEST(e) ((e)->to_room)
#define EXIT_DEST(e) (EXIT_NDEST(e) == NOWHERE ? NULL : &world[EXIT_NDEST(e)])
Expand Down
2 changes: 1 addition & 1 deletion include/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/* handling the affected-structures */
void effect_total(CharData *ch);
void do_campout(CharData *ch);
void effect_modify(CharData *ch, byte loc, sh_int mod, flagvector bitv[], bool add);
void effect_modify(CharData *ch, byte loc, sh_int mod, EffectFlags flags, bool add);
void effect_to_char(CharData *ch, effect *eff);
void effect_remove(CharData *ch, effect *eff);
void active_effect_remove(CharData *ch, effect *effect);
Expand Down
16 changes: 8 additions & 8 deletions include/objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#pragma once

#include "effects.hpp"
#include "events.hpp"
#include "structs.hpp"
#include "sysdep.hpp"

Expand Down Expand Up @@ -44,15 +45,15 @@ struct ObjectFlagData {
byte type_flag; /* Type of item */
long int wear_flags; /* Where you can wear it */
/* If it hums, glows, etc. */
flagvector extra_flags[FLAGVECTOR_SIZE(NUM_ITEM_FLAGS)];
ExtraObjectFlags extra_flags;
float weight; /* Weight what else */
float effective_weight; /* Weight of contents + weight */
int cost; /* Value when sold (gp.) */
int level; /* Level of the object */
int timer; /* Timer for object */
int decomp; /* Decomposition timer */
/* Object Spell effects */
flagvector effect_flags[FLAGVECTOR_SIZE(NUM_EFF_FLAGS)];
EffectFlags effect_flags;
long hiddenness; /* How difficult it is to see obj */
};

Expand Down Expand Up @@ -92,10 +93,9 @@ struct ObjData {

SpellBookList *spell_book; /* list of all spells in book if obj is spellbook */

CharData *casters; /* Characters who are casting spells at this */
Event *events; /* List of events related to this object */
int event_flags[EVENT_FLAG_FIELDS];
/* Bitfield of events active on this object */
CharData *casters; /* Characters who are casting spells at this */
Event *events; /* List of events related to this object */
EventFlags event_flags; /* Bitfield of events active on this object */
};

/*
Expand Down Expand Up @@ -560,8 +560,8 @@ const struct LiquidDef liquid_types[NUM_LIQ_TYPES] = {
#define GET_OBJ_RNUM(obj) ((obj)->item_number)
#define GET_OBJ_VNUM(obj) (GET_OBJ_RNUM(obj) >= 0 ? obj_index[GET_OBJ_RNUM(obj)].vnum : -1)
#define GET_OBJ_EFF_FLAGS(obj) ((obj)->obj_flags.effect_flags)
#define OBJ_FLAGGED(obj, flag) (IS_FLAGGED(GET_OBJ_FLAGS(obj), (flag)))
#define OBJ_EFF_FLAGGED(obj, f) (IS_FLAGGED(GET_OBJ_EFF_FLAGS(obj), (f)))
#define OBJ_FLAGGED(obj, flag) (GET_OBJ_FLAGS(obj).test((flag)))
#define OBJ_EFF_FLAGGED(obj, f) (GET_OBJ_EFF_FLAGS(obj).test((f)))
#define GET_OBJ_SPEC(obj) ((obj)->item_number >= 0 ? (obj_index[(obj)->item_number].func) : NULL)
#define CAN_WEAR(obj, part) (IS_SET(GET_OBJ_WEAR(obj), (part)))

Expand Down
34 changes: 32 additions & 2 deletions include/players.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

#pragma once

#include "db.hpp"
#include "interpreter.hpp"
#include "logging.hpp"
#include "string_utils.hpp"
#include "structs.hpp"
#include "sysdep.hpp"

Expand Down Expand Up @@ -51,9 +55,35 @@ void start_player(CharData *ch);

void add_perm_title(CharData *ch, char *line);

void load_ascii_flags(flagvector flags[], int num_flags, char *line);
void write_ascii_flags(FILE *fl, flagvector flags[], int num_flags);
template <size_t N> void load_ascii_flags(std::bitset<N> &flags, char *line) {
int i = 0;

skip_spaces(&line);

line = strtok(line, " ");

while (line && *line) {
if (flags.size() <= i) {
if (*line != '0') {
log("SYSERR: load_ascii_flags: attempting to read in flags for block {:d}, but only {} blocks allowed "
"for std::bitset type",
i, flags.size());
}
} else
flags[i] = asciiflag_conv(line);
line = strtok(nullptr, " ");
++i;
}
}

template <size_t N> void write_ascii_flags(FILE *fl, const std::bitset<N> &flags) {
char flagbuf[flags.size() + 1];

for (int i = 0; i < flags.size(); ++i) {
sprintascii(flagbuf, flags);
fprintf(fl, "%s%s", i ? " " : "", flagbuf);
}
}
void remove_player_from_game(CharData *ch, int removal_mode);
void send_save_description(CharData *ch, CharData *dest, bool entering);

Expand Down
Loading