indexing description: "Dragon actors" author: "Remlie Ortencio" date: "13-10-2012" last_modified: "13-10-2012" class DRAGON inherit HOBBIT_ACTOR redefine make, act end create {HOBBIT_OBJECT_FACTORY} -- a DRAGON can only be created by a -- HOBBIT_OBJECT_FACTORY make feature{NONE} -- private attributes sleeping: BOOLEAN -- check on whether dragon is awake or asleep hoard_location: LOCATION -- records where dragon's hoard is to allow it to return travel_direction: INTEGER -- index into directions next_location: LOCATION -- where the dragon is to move next attack_command: ATTACK_COMMAND -- our own private attack command, which we will not make visible to others feature{NONE} -- creation make(new_name: STRING; new_description: STRING; the_simulation: HOBBIT_SIMULATION) is local weapon: OBJECT take_command: TAKE_COMMAND do precursor(new_name, new_description, the_simulation) -- give the dragon an "active attack" command, which it will use to attack other actors it encounters -- this is different from the "passive" attack commands that all HOBBIT_ACTOR actors have, that allows them to be attacked create attack_command.make ("active attack", "") attack_command.set_actor(current) -- Give the dragon jaws of fire, as blasting actors with fire is what they do best -- Handled this way for simplicity, will need to handle deletion of weapon upon defeat (if ever possible, assumed immortal from currently implemented attacks) weapon := simulation.object_factory.create_object(new_name + "'s Jaws of Fire", "the dragon's source of deathly hot flames") weapon.set_symbol('') -- research on what this means and what symbol to use create take_command.make("take", "") take_command.set_object(weapon) weapon.add_command(take_command) weapon.set_points(999,999) -- assuming this is damage points, research required take_command.set_actor(current) take_command.execute -- doing it this way ensures that house-keeping is done -- initialize behaviour sleeping := TRUE -- sleeps and does nothing until it wakes end -- make feature -- game action act is -- the Dragon behaviour for The Hobbit game require else valid_location: location /= void -- the location must be set before the first call to act, as this defines the dragon's hoard's location local wake_chance: INTEGER -- holds a value between 1 to 10 to determine when dragon wakes do -- ### Initial Behaviour if hoard_location = void then hoard_location := location -- set the hoard location on the first call to act end if sleeping = TRUE then -- Dragon is still asleep -- code to wake up dragon at a 10% chance here wake_chance := simulation.random_generator.random_value_from_range(1, 10) if wake_chance = 1 then sleeping := FALSE simulation.interface.put_message(name + " has woken up!") set_up_travel -- decides where to go upon waking end -- inner if else move if location = hoard_location then sleeping := TRUE else attack end -- else if end -- outer if end -- act feature{NONE} -- private meathods set_up_travel is -- method to decide where the dragon will move to next local location_check: LOCATION do travel_direction := simulation.random_generator.random_value_from_range(directions.lower, directions.upper) location_check := location.get_path(directions.item(travel_direction)) if location_check = void then set_up_travel -- should call itself until a valid direction is found, for when dragon is sleeping at edge of grid end end -- set_up_travel move is -- handles dragon moving from hoard and back -- navigation used to return to hoard here is the same as the method used in the REPLICATOR class -- this form of navigation is used in case dragon encounters water (while unlikely, used just in case) -- Note: does not handle if dragon is moving against water current local next_location: LOCATION current_direction: INTEGER do if location /= hoard_location then from current_direction := directions.lower until current_direction >= directions.upper loop next_location := get_closer_location(current_target.location, next_location, location.get_path(directions.item(current_direction))) current_direction := current_direction + 1 end -- loop else next_location := location.get_path(directions.item(travel_direction)) end set_location(next_location) end -- move attack is -- handles dragon attacking when it finds visible actor(s) in the area it is currently in local obj_list: LINKED_LIST[STRING] obj: OBJECT attack_obj_list: LINKED_LIST[STRING] number_of_attack_areas: INTEGER attack_command : ATTACK_COMMAND do obj_list := location.list_contents if obj_list /= void then from obj_list.start until obj_list.off loop obj := location.get_contents(object_name_from_list_entry(obj_list.item)) if obj.team_id /= simulation.default_team_id and obj.team_id /= team_id then if obj.has_command("attack") then -- we have found something to attack -- replace following code with code to attack all actors in the area, invisible or not attack_command ?= obj.get_command("attack") if attack_command /= void then attack_command.set_actor(obj) attack_command.execute attack_command.set_actor(void) end emd simulation.interface.put_message("An attack has been launched! " + name + weapon.get_name + " damages everyone in the area!") number_of_attack_areas := 1 -- fixed assuming there is 9 areas, one in each of the 8 directions and the current area from number_of_attack_areas = 1 until number_of_attack_areas = 9 loop end end -- if obj_list.forth end -- loop end -- if end -- attack -- TODO: -- Make Dragon sleep with 10% chance of waking -- When awake, make it move in one random direction, then check if actor can be seen in the area the dragon moved to -- if visible actor exists, then attack, which also damages all actors in the area and all adjacent areas -- after moving/attacking, go back to hoard -- add treasure objects (look at hobbit_application object_factory) end