hivemind_schema.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #hivemind
  2. schema and examples
  3. The heart of hivemind beats with the rhythm of encounters, the hivemind is shared among entities.
  4. ```
  5. hivemind.encounter (self, clicker, {relation_name = 1})
  6. ```
  7. the mob first creates its own identifier
  8. All encounters between an entity (generally a player) and a mob are recorded as follows
  9. schema:
  10. self.hivemind = {
  11. "id" = math.rand (or {territory, name}, etc...)
  12. k: [id] = {
  13. v/x: [entity] = {
  14. y: [relation_name] = value,
  15. [another_relation] = value,
  16. fe = value (generated from os.time),
  17. le = value (generated from os.time)
  18. }
  19. },
  20. k: [another_id] = {
  21. v/x: [entity] = {
  22. y: [relation_name] = value,
  23. [another_relation] = value,
  24. fe = value (generated from os.time),
  25. le = value (generated from os.time)
  26. }
  27. },
  28. }
  29. * mobs can then transfer relations first by comparing time stamps of "le" (last encounter) from each [id],[entity].le pair
  30. * if the remote mob has a new or newer dataset for [id][entity] then the local mob dataset for that [id][entity] is added or replaced.
  31. * manipulation of the remotes own dataset should be conducted by that mob with the same function otherwise this can become redundant
  32. * with relations recorded, mobs can simply add the relation values to get data on how to react during an entity encounter
  33. * we could use relations to keep track of which ids belong to a certain group (such as territory) to determine what is relavent
  34. example using mobs_redo:
  35. init.lua:
  36. ```
  37. if minetest.get_modpath("hivemind") then
  38. print("hivemind mod detected")
  39. mymod.hivemind = 1
  40. end
  41. ```
  42. in your mob definition:
  43. ```
  44. do_custom = function(self)
  45. if mymod.hivemind then
  46. hivemind.pull(self)
  47. end
  48. end,
  49. do_punch = function(self,hitter)
  50. if mymod.hivemind then
  51. hivemind.encounter (self, hitter, {naughty = 2})
  52. print(dump(hivemind.encounter(self)))
  53. end
  54. end,
  55. on_rightclick = function(self,clicker)
  56. if mymod.hivemind then
  57. hivemind.encounter (self, clicker, {nice = 1})
  58. print(dump(hivemind.encounter(self)))
  59. end
  60. end,
  61. ```
  62. when making a query against an entity, we can make a simple function like this to get a score (assuming "naughty" is a relation in this example)
  63. ```
  64. local function get_aggro(self,target) -- how aggressive is this entity?
  65. local naughty = 0 --assume the best :D
  66. for k,v in pairs(self.hivemind) do
  67. if k = id then end --we can ignore this, it only identifies us
  68. else -- we want to know how the target has treated others that we have talked to!
  69. if v = target and then
  70. naughty = naughty + v.naughty
  71. end
  72. end
  73. return naughty --the total naughty to all entity friends
  74. end
  75. end
  76. ```
  77. we could then compare results of "naughty" and "nice" among groups of mobs as well anything else you could want such as how long a mob has been "alive", "hungry", "exposed" to radiation, etc.
  78. ##TL;DR:
  79. * Define or update a table with key(s) and value(s) when you call:
  80. hivemind.encounter(self, entity, {something_to_track = 1})
  81. * Omit the optional params for queries
  82. * Call hivemind.pull(self) to look for other entities encounters for further processing