Advertisement
ArranUbels

Untitled

Oct 14th, 2012
2,916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 7.00 KB | None | 0 0
  1. indexing
  2.     description: "Dragon actors"
  3.     author: "Remlie Ortencio"
  4.     date: "13-10-2012"
  5.     last_modified: "13-10-2012"
  6.  
  7. class
  8.     DRAGON
  9.  
  10. inherit
  11.     HOBBIT_ACTOR
  12.         redefine
  13.             make, act
  14.         end
  15.  
  16. create {HOBBIT_OBJECT_FACTORY} -- a DRAGON can only be created by a
  17.                                -- HOBBIT_OBJECT_FACTORY
  18.     make
  19.  
  20. feature{NONE} -- private attributes
  21.  
  22.     sleeping: BOOLEAN -- check on whether dragon is awake or asleep
  23.     hoard_location: LOCATION -- records where dragon's hoard is to allow it to return
  24.     travel_direction: INTEGER -- index into directions
  25.     next_location: LOCATION -- where the dragon is to move next
  26.     attack_command: ATTACK_COMMAND -- our own private attack command, which we will not make visible to others
  27.  
  28. feature{NONE} -- creation
  29.     make(new_name: STRING; new_description: STRING; the_simulation: HOBBIT_SIMULATION) is
  30.         local
  31.             weapon: OBJECT
  32.             take_command: TAKE_COMMAND
  33.         do
  34.             precursor(new_name, new_description, the_simulation)
  35.  
  36.             -- give the dragon an "active attack" command, which it will use to attack other actors it encounters
  37.             -- this is different from the "passive" attack commands that all HOBBIT_ACTOR actors have, that allows them to be attacked
  38.             create attack_command.make ("active attack", "<actor>")
  39.             attack_command.set_actor(current)
  40.  
  41.             -- Give the dragon jaws of fire, as blasting actors with fire is what they do best
  42.             -- Handled this way for simplicity, will need to handle deletion of weapon upon defeat (if ever possible, assumed immortal from currently implemented attacks)
  43.             weapon := simulation.object_factory.create_object(new_name + "'s Jaws of Fire", "the dragon's source of deathly hot flames")
  44.             weapon.set_symbol('') -- research on what this means and what symbol to use
  45.             create take_command.make("take", "<object>")
  46.             take_command.set_object(weapon)
  47.             weapon.add_command(take_command)
  48.             weapon.set_points(999,999) -- assuming this is damage points, research required
  49.             take_command.set_actor(current)
  50.             take_command.execute -- doing it this way ensures that house-keeping is done
  51.  
  52.             -- initialize behaviour
  53.             sleeping := TRUE -- sleeps and does nothing until it wakes
  54.         end -- make
  55.  
  56. feature -- game action
  57.     act is
  58.             -- the Dragon behaviour for The Hobbit game
  59.         require else
  60.             valid_location: location /= void -- the location must be set before the first call to act, as this defines the dragon's hoard's location
  61.         local
  62.             wake_chance: INTEGER -- holds a value between 1 to 10 to determine when dragon wakes
  63.         do
  64.             -- ### Initial Behaviour
  65.             if hoard_location = void then
  66.                 hoard_location := location -- set the hoard location on the first call to act
  67.             end
  68.  
  69.             if sleeping = TRUE then
  70.                 -- Dragon is still asleep
  71.                 -- code to wake up dragon at a 10% chance here
  72.                 wake_chance := simulation.random_generator.random_value_from_range(1, 10)
  73.                 if wake_chance = 1 then
  74.                     sleeping := FALSE
  75.                     simulation.interface.put_message(name + " has woken up!")
  76.                     set_up_travel -- decides where to go upon waking
  77.                 end -- inner if
  78.             else
  79.                 move
  80.                 if location = hoard_location then
  81.                     sleeping := TRUE
  82.                 else
  83.                     attack
  84.                 end -- else if
  85.             end -- outer if
  86.         end -- act
  87.  
  88. feature{NONE} -- private meathods
  89.     set_up_travel is
  90.             -- method to decide where the dragon will move to next
  91.         local
  92.             location_check: LOCATION
  93.         do
  94.             travel_direction := simulation.random_generator.random_value_from_range(directions.lower, directions.upper)
  95.             location_check := location.get_path(directions.item(travel_direction))
  96.             if location_check = void then
  97.                 set_up_travel -- should call itself until a valid direction is found, for when dragon is sleeping at edge of grid
  98.             end
  99.         end -- set_up_travel
  100.  
  101.     move is
  102.             -- handles dragon moving from hoard and back
  103.             -- navigation used to return to hoard here is the same as the method used in the REPLICATOR class
  104.             -- this form of navigation is used in case dragon encounters water (while unlikely, used just in case)
  105.             -- Note: does not handle if dragon is moving against water current
  106.         local
  107.             next_location: LOCATION
  108.             current_direction: INTEGER
  109.         do
  110.             if location /= hoard_location then
  111.                 from
  112.                     current_direction := directions.lower
  113.                 until
  114.                     current_direction >= directions.upper
  115.                 loop
  116.                     next_location := get_closer_location(current_target.location, next_location, location.get_path(directions.item(current_direction)))
  117.                     current_direction := current_direction + 1
  118.                 end -- loop
  119.             else
  120.                 next_location := location.get_path(directions.item(travel_direction))
  121.             end
  122.             set_location(next_location)
  123.         end -- move
  124.  
  125.     attack is
  126.             -- handles dragon attacking when it finds visible actor(s) in the area it is currently in
  127.     local
  128.         obj_list: LINKED_LIST[STRING]
  129.         obj: OBJECT
  130.         attack_obj_list: LINKED_LIST[STRING]
  131.         attack_area: INTEGER
  132.         next_location: LOCATION -- next location to check what area to apply attack commands in
  133.         attack_area_list: LINKED_LIST[STRING]
  134.         attack_obj: OBJECT
  135.     do
  136.         obj_list := location.list_contents
  137.         if obj_list /= void then
  138.             from
  139.                 obj_list.start
  140.             until
  141.                 obj_list.off
  142.             loop
  143.                 obj := location.get_contents(object_name_from_list_entry(obj_list.item))
  144.                 if obj.team_id /= simulation.default_team_id and obj.team_id /= team_id then
  145.                     -- we have found something to attack
  146.                     -- replace following code with code to attack all actors in the area, invisible or not
  147.                     --attack_command.set_object(obj)
  148.                     --attack_command.execute
  149.                     simulation.interface.put_message("An attack has been launched! " + name + weapon.get_name + " damages everyone in the area!")
  150.                     from
  151.                         attack_area := directions.lower
  152.                     until
  153.                         attack_area >= directions.upper + 1
  154.                     loop
  155.                         next_location := location.get_path(directions.item(attack_area)))
  156.                         -- area attack code here
  157.                         attack_area_list := next_location.list_contents
  158.                         if attack_area_list /= void then
  159.                             from
  160.                                 attack_area_list.start
  161.                             until
  162.                                 attack_area_list.off
  163.                             loop
  164.                                 attack_obj := location.get_contents(object_name_from_list_entry(attack_area_list.item))
  165.                                 if attack_obj.team_id /= simulation.default_team_id and attack_obj.team_id /= team_id then
  166.                                     -- we have found something to attack
  167.                                                 attack_command.set_actor(current)
  168. -- attack_command.set_object(attack_obj)
  169.                                     attack_command.execute
  170. attack_command.set_actor(void)
  171.                                 end -- if
  172.                                 attack_area_list.forth
  173.                             end -- loop
  174.                         end -- if
  175.                         -- area attack code end
  176.                         attack_area := attack_area + 1
  177.                     end
  178.                 end -- if
  179.                 obj_list.off
  180.             end -- loop
  181.         end -- if
  182.     end -- attack
  183.  
  184.     -- TODO:
  185.     -- Make Dragon sleep with 10% chance of waking
  186.     -- When awake, make it move in one random direction, then check if actor can be seen in the area the dragon moved to
  187.     -- if visible actor exists, then attack, which also damages all actors in the area and all adjacent areas
  188.     -- after moving/attacking, go back to hoard
  189.     -- add treasure objects (look at hobbit_application object_factory)
  190. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement