mud.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //*****************************************************************************
  2. //
  3. // mud.c
  4. //
  5. // a bunch of variables and settings associated with the functioning, limits,
  6. // and such of the MUD.
  7. //
  8. //*****************************************************************************
  9. #include "mud.h"
  10. #include "utils.h"
  11. #include "storage.h"
  12. //*****************************************************************************
  13. // local defines, variables, and datastructures
  14. //*****************************************************************************
  15. //
  16. // the file where we store all of our mud settings
  17. #define MUD_DATA "../lib/muddata"
  18. //
  19. // our storage set of mud settings
  20. STORAGE_SET *settings = NULL;
  21. //
  22. // for generating unique IDs to characters, rooms, objects, exits, etc
  23. int next_available_uid = START_UID;
  24. int next_uid(void) {
  25. return next_available_uid++;
  26. }
  27. int top_uid(void) {
  28. if(next_available_uid == START_UID)
  29. return NOTHING;
  30. return next_available_uid - 1;
  31. }
  32. //*****************************************************************************
  33. // implementation of functions in mud.h
  34. //*****************************************************************************
  35. void init_mud_settings() {
  36. settings = storage_read(MUD_DATA);
  37. // make sure we have initial values for some stuff
  38. if(!*mudsettingGetString("start_room"))
  39. mudsettingSetString("start_room", DFLT_START_ROOM);
  40. if(mudsettingGetInt("pulses_per_second") == 0)
  41. mudsettingSetInt("pulses_per_second", DFLT_PULSES_PER_SECOND);
  42. }
  43. void mudsettingSetString(const char *key, const char *val) {
  44. store_string(settings, key, val);
  45. storage_write(settings, MUD_DATA);
  46. }
  47. void mudsettingSetDouble(const char *key, double val) {
  48. store_double(settings, key, val);
  49. storage_write(settings, MUD_DATA);
  50. }
  51. void mudsettingSetInt(const char *key, int val) {
  52. store_int(settings, key, val);
  53. storage_write(settings, MUD_DATA);
  54. }
  55. void mudsettingSetLong(const char *key, long val) {
  56. store_long(settings, key, val);
  57. storage_write(settings, MUD_DATA);
  58. }
  59. void mudsettingSetBool(const char *key, bool val) {
  60. store_bool(settings, key, val);
  61. storage_write(settings, MUD_DATA);
  62. }
  63. const char *mudsettingGetString(const char *key) {
  64. return read_string(settings, key);
  65. }
  66. double mudsettingGetDouble(const char *key) {
  67. return read_double(settings, key);
  68. }
  69. int mudsettingGetInt(const char *key) {
  70. return read_int(settings, key);
  71. }
  72. long mudsettingGetLong(const char *key) {
  73. return read_long(settings, key);
  74. }
  75. bool mudsettingGetBool(const char *key) {
  76. return read_bool(settings, key);
  77. }