cyphesis/rulesets/TaskScript.cpp
Al Riddoch c111c29826 2005-12-09 Al Riddoch <alriddoch@zepler.org>
* rulesets/Script.cpp: Document the script interface.

	* rulesets/Task.h: Modify task interface so tasks now expect
	  the operation that initiated the task to be passed in
	  to an init function.

	* rulesets/Combat.h, rulesets/Combat.cpp: Modify the combat task
	  methods to match the interface changes.

	* rulesets/Character.cpp: Modify Combat use to take account
	  of interface changes. Prototype using script based
	  combat.

	* rulesets/TaskScript.h, rulesets/TaskScript.cpp: Implement
	  passing the initialising op through to the script using the
	  standard scripp operation handling functions.

	* rulesets/mason/world/tasks/Combat.py: Add handler for Attack
	  operation, which should now be passed in at init time.
2005-12-09 09:33:17 +00:00

49 lines
1.1 KiB
C++

// This file may be redistributed and modified only under the terms of
// the GNU General Public License (See COPYING for details).
// Copyright (C) 2005 Alistair Riddoch
#include "rulesets/TaskScript.h"
#include "rulesets/Script.h"
#include "common/log.h"
#include <Atlas/Objects/SmartPtr.h>
#include <Atlas/Objects/RootOperation.h>
TaskScript::TaskScript(Character & chr) : Task(chr), m_script(0)
{
}
TaskScript::~TaskScript()
{
}
void TaskScript::setScript(Script * scrpt)
{
if (m_script != 0) {
log(WARNING, "Installing a new task script over an existing script");
delete m_script;
}
m_script = scrpt;
}
void TaskScript::irrelevant()
{
Task::irrelevant();
}
void TaskScript::initTask(const Operation & op, OpVector & res)
{
assert(m_script != 0);
if (!m_script->operation(op->getParents().front(), op, res)) {
log(WARNING, "Task init failed");
irrelevant();
}
}
void TaskScript::TickOperation(const Operation & op, OpVector & res)
{
assert(m_script != 0);
m_script->operation("tick", op, res);
}