Class: Quake::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/quake/entity.rb

Overview

Represents a parsed entity from the BSP entities lump. All Quake entities (players, monsters, items, triggers, brush models) are defined as key-value property bags in the BSP entity string.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties = {}) ⇒ Entity

Returns a new instance of Entity.



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
# File 'lib/quake/entity.rb', line 13

def initialize(properties = {})
  @properties = properties
  @classname = properties["classname"] || ""

  # Parse common fields
  @position = parse_vec3(properties["origin"]) || Math::Vec3::ORIGIN
  @angle = (properties["angle"] || "0").to_f
  @angles = parse_vec3(properties["angles"]) || Math::Vec3::ORIGIN

  # Brush model reference: "*1", "*2", etc.
  @model_index = nil
  if (model_str = properties["model"])
    @model_index = model_str[1..].to_i if model_str.start_with?("*")
  end

  # Targeting
  @target = properties["target"]
  @targetname = properties["targetname"]

  # Movement/behavior
  @speed = (properties["speed"] || default_speed).to_f
  @wait = (properties["wait"] || "3").to_f
  @lip = (properties["lip"] || "8").to_f
  @health = (properties["health"] || "0").to_f
  @sounds = (properties["sounds"] || "0").to_i
  @message = properties["message"]

  # Runtime state
  @state = :idle
  @think_time = 0.0
  @move_dir = Math::Vec3::ORIGIN
end

Instance Attribute Details

#angleObject

Returns the value of attribute angle.



8
9
10
# File 'lib/quake/entity.rb', line 8

def angle
  @angle
end

#anglesObject

Returns the value of attribute angles.



8
9
10
# File 'lib/quake/entity.rb', line 8

def angles
  @angles
end

#classnameObject

Returns the value of attribute classname.



8
9
10
# File 'lib/quake/entity.rb', line 8

def classname
  @classname
end

#healthObject

Returns the value of attribute health.



8
9
10
# File 'lib/quake/entity.rb', line 8

def health
  @health
end

#lipObject

Returns the value of attribute lip.



8
9
10
# File 'lib/quake/entity.rb', line 8

def lip
  @lip
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/quake/entity.rb', line 8

def message
  @message
end

#model_indexObject

Returns the value of attribute model_index.



8
9
10
# File 'lib/quake/entity.rb', line 8

def model_index
  @model_index
end

#move_dirObject

Returns the value of attribute move_dir.



8
9
10
# File 'lib/quake/entity.rb', line 8

def move_dir
  @move_dir
end

#positionObject

Returns the value of attribute position.



8
9
10
# File 'lib/quake/entity.rb', line 8

def position
  @position
end

#propertiesObject

Returns the value of attribute properties.



8
9
10
# File 'lib/quake/entity.rb', line 8

def properties
  @properties
end

#soundsObject

Returns the value of attribute sounds.



8
9
10
# File 'lib/quake/entity.rb', line 8

def sounds
  @sounds
end

#speedObject

Returns the value of attribute speed.



8
9
10
# File 'lib/quake/entity.rb', line 8

def speed
  @speed
end

#stateObject

Returns the value of attribute state.



8
9
10
# File 'lib/quake/entity.rb', line 8

def state
  @state
end

#targetObject

Returns the value of attribute target.



8
9
10
# File 'lib/quake/entity.rb', line 8

def target
  @target
end

#targetnameObject

Returns the value of attribute targetname.



8
9
10
# File 'lib/quake/entity.rb', line 8

def targetname
  @targetname
end

#think_timeObject

Returns the value of attribute think_time.



8
9
10
# File 'lib/quake/entity.rb', line 8

def think_time
  @think_time
end

#waitObject

Returns the value of attribute wait.



8
9
10
# File 'lib/quake/entity.rb', line 8

def wait
  @wait
end

Instance Method Details

#[](key) ⇒ Object



46
# File 'lib/quake/entity.rb', line 46

def [](key) = @properties[key]

#brush_entity?Boolean

Returns:

  • (Boolean)


48
# File 'lib/quake/entity.rb', line 48

def brush_entity? = !@model_index.nil?

#forward_vectorObject

Direction vector from the “angle” field (Quake convention)



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/quake/entity.rb', line 51

def forward_vector
  case @angle.to_i
  when -1 # UP
    Math::Vec3.new(0.0, 0.0, 1.0)
  when -2 # DOWN
    Math::Vec3.new(0.0, 0.0, -1.0)
  else
    rad = @angle * ::Math::PI / 180.0
    Math::Vec3.new(::Math.cos(rad), ::Math.sin(rad), 0.0)
  end
end