Skip to content

Commit

Permalink
ADDED move event to track character movement and entering/exitting of…
Browse files Browse the repository at this point in the history
… zones
  • Loading branch information
ksterker committed Feb 26, 2012
1 parent d2fc178 commit eff4eff
Show file tree
Hide file tree
Showing 12 changed files with 518 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/py-wrappers/adonthell/py_world.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "world/character.h"
#include "world/mapview.h"
#include "world/schedule.h"
#include "world/move_event.h"

using namespace world;

Expand All @@ -18,7 +19,8 @@ using namespace world;
%include "std_string.i"

%import "base/types.h"
%import "py_gfx.i"
%import(module="event") "event/event.h"
%import(module="gfx") "gfx/drawable.h"

// typemap for returning a string pointer as python string
%typemap(out) std::string * {
Expand Down Expand Up @@ -48,6 +50,7 @@ using namespace world;
%include "world/placeable.h"
%include "world/object.h"
%include "world/coordinates.h"
%include "world/move_event.h"
%include "world/moving.h"
%include "world/action.h"
%include "world/character.h"
Expand Down
24 changes: 14 additions & 10 deletions src/world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set(adonthell_world_SRCS
chunk.cc
chunk_info.cc
mapview.cc
move_event.cc
move_event_manager.cc
moving.cc
object.cc
placeable.cc
Expand Down Expand Up @@ -37,29 +39,31 @@ set(adonthell_world_HEADERS
chunk_info.h
entity.h
mapview.h
move_event.h
move_event_manager.h
moving.h
node.h
node_cache.h
node_bank.h
node.h
node_cache.h
node_bank.h
object.h
open_list.h
open_list.h
placeable.h
placeable_model.h
placeable_shape.h
plane3.h
pathfinding.h
pathfinding_manager.h
pathfinding_task.h
pathfinding.h
pathfinding_manager.h
pathfinding_task.h
render_info.h
renderer.h
schedule.h
schedule_data.h
schedule.h
schedule_data.h
shadow.h
shadow_info.h
triangle3.h
vector3.h
world.h
zone.h
zone.h
)


Expand Down
4 changes: 4 additions & 0 deletions src/world/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pkgincludeworld_HEADERS = \
cube3.h \
entity.h \
mapview.h \
move_event.h \
move_event_manager.h \
moving.h \
node_bank.h \
node_cache.h \
Expand Down Expand Up @@ -53,6 +55,8 @@ libadonthell_world_la_SOURCES = \
collision.cc \
cube3.cc \
mapview.cc \
move_event.cc \
move_event_manager.cc \
moving.cc \
object.cc \
placeable.cc \
Expand Down
2 changes: 1 addition & 1 deletion src/world/area.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void area::remove_zone (world::zone * zone)
}

// retrieve zone with a certain name
world::zone * area::get_zone (std::string & name)
world::zone * area::get_zone (const std::string & name) const
{
std::list<world::zone *>::const_iterator i;

Expand Down
2 changes: 1 addition & 1 deletion src/world/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace world
* @return a pointer to the zone, or NULL on error
* @note name is case-sensitive
*/
world::zone *get_zone(std::string & name);
world::zone *get_zone(const std::string & name) const;

/**
* Return all zones that contain the given point of given type.
Expand Down
105 changes: 105 additions & 0 deletions src/world/move_event.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Copyright (C) 2012 Kai Sterker <kai.sterker@gmail.com>
Part of the Adonthell Project http://adonthell.nongnu.org
Adonthell is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Adonthell is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Adonthell; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/**
* @file world/move_event.cc
*
* @author Kai Sterker
* @brief Declares the move_event class.
*/

#include "base/logging.h"
#include "world/move_event.h"
#include "world/area_manager.h"

using world::move_event;

// constructor
move_event::move_event (const world::area *map, const std::string & actor, const std::string & check_enter, const std::string & check_leave)
{
Actor = (world::moving *) map->get_entity(actor);
CheckEnter = map->get_zone(check_enter);
CheckLeave = map->get_zone(check_leave);

if (check_leave != check_enter && check_leave != "")
{
LOG(WARNING) << "move_event: ignoring leave check (must be same as enter or \"\")";
CheckLeave = NULL;
}
}

// test two move events for equality
bool move_event::equals (const events::event * e) const
{
const move_event *evt = (const move_event*) e;

// actor && (enter || leave)
if (Actor != evt->actor()) return false;

bool equals = true;

if (CheckEnter != NULL)
{
if (!CheckEnter->contains (evt->start()) && CheckEnter->contains(evt->end())) equals = true;
else equals = false;
}

if (CheckLeave != NULL)
{
if (CheckLeave->contains (evt->start()) && !CheckLeave->contains(evt->end())) equals = true;
else equals = false;
}

return equals;
}

// save move event
void move_event::put_state (base::flat& file) const
{
// save basic event data first
event::put_state (file);

// save move event data
file.put_string ("mva", Actor ? Actor->uid() : "");
file.put_string ("mve", CheckEnter ? CheckEnter->name() : "");
file.put_string ("mvl", CheckLeave ? CheckLeave->name() : "");
}

// load move event
bool move_event::get_state (base::flat& file)
{
// get basic event data
if (event::get_state (file))
{
const world::area *map = world::area_manager::get_map();

// get move event data
std::string actor = file.get_string("mva");
if (actor != "") Actor = (world::moving*) map->get_entity(actor);

std::string check_enter = file.get_string("mve");
if (check_enter != "") CheckEnter = map->get_zone(check_enter);

std::string check_leave = file.get_string("mvl");
if (check_leave != "") CheckLeave = map->get_zone(check_leave);
}

return file.success ();
}

Loading

0 comments on commit eff4eff

Please sign in to comment.