File: lm_mon_prop.lua

package info (click to toggle)
crawl 2%3A0.33.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,264 kB
  • sloc: cpp: 358,145; ansic: 27,203; javascript: 9,491; python: 8,359; perl: 3,327; java: 2,667; xml: 2,191; makefile: 1,830; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (65 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download | duplicates (5)
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
------------------------------------------------------------------------------
-- lm_mon_prop.lua:
--
-- This marker takes whatever monster is standing on it, sets properties in
-- the CrawlHashTable member of that monster, then disappears.
------------------------------------------------------------------------------

MonPropsMarker = { CLASS = "MonPropsMarker" }
MonPropsMarker.__index = MonPropsMarker

function MonPropsMarker:new(props)
  if not props then
    error("MonPropsMarker:new() needs props")
  end
  if type(props) ~= "table" then
    error("MonPropsMarker:new() needs type(props) == table")
  end

  local mp = { }
  setmetatable(mp, self)
  self.__index = self

  mp.props = props

  return mp
end

function MonPropsMarker:init(marker)
  -- use init, not activate, so that the properties can get transferred to the
  -- monster immediately on level generation, rather than requiring the player
  -- to enter the level.
  local mon = dgn.mons_at(marker:pos())

  if not mon then
    crawl.mpr("No monster for MonPropsMarker:activate()")
    dgn.remove_marker(marker)
    return
  end

  for k, v in pairs(self.props) do
    mon.set_prop(k, v)
  end

  -- NOTE: do *not* call dgn.remove_marker() right now; removing a marker
  -- while it's being activated causes memory problems. We'll be
  -- removed after activation is done with the "post_activate_remove"
  -- property.
  self.want_remove = true
end

function MonPropsMarker:property(marker, pname)
  if self.want_remove and pname == "post_init_remove" then
    return "true"
  end

  return ""
end

function MonPropsMarker:write(marker, th)
  error("MonPropsMarker should never be saved")
end

function MonPropsMarker:read(marker, th)
  error("MonPropsMarker should never be in save file")
end