[+] Added teleport spell

This commit is contained in:
cybermind 2013-04-15 20:39:16 +06:00
parent 87d7fa5a87
commit a4b526c42c
5 changed files with 138 additions and 1 deletions

View file

@ -275,6 +275,7 @@ set(spell_SRCS
src/spell/spell_spawnmissile.cpp
src/spell/spell_spawnportal.cpp
src/spell/spell_summon.cpp
src/spell/spell_teleport.cpp
src/spell/spells.cpp
)
source_group(spell FILES ${spell_SRCS})
@ -500,6 +501,7 @@ set(stratagus_spell_HDRS
src/include/spell/spell_spawnmissile.h
src/include/spell/spell_spawnportal.h
src/include/spell/spell_summon.h
src/include/spell/spell_teleport.h
)
set(stratagus_generic_HDRS

View file

@ -0,0 +1,57 @@
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
//
// (c) Copyright 2013 by cybermind
//
// This program 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; only version 2 of the License.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
#ifndef SPELL_TELEPORT_H
#define SPELL_TELEPORT_H
//@{
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
#include "spells.h"
class Spell_Teleport : public SpellActionType
{
public:
Spell_Teleport() : SpellActionType(1), UnitType(NULL), TTL(0), RequireCorpse(0) {};
virtual int Cast(CUnit &caster, const SpellType &spell,
CUnit *target, const Vec2i &goalPos);
virtual void Parse(lua_State *l, int startIndex, int endIndex);
private:
CUnitType *UnitType; /// Type of unit to be summoned.
int TTL; /// Time to live for summoned unit. 0 means infinite
int RequireCorpse; /// Corpse consumed while summoning.
};
//@}
#endif // SPELL_TELEPORT_H

View file

@ -46,6 +46,7 @@
#include "spell/spell_spawnmissile.h"
#include "spell/spell_spawnportal.h"
#include "spell/spell_summon.h"
#include "spell/spell_teleport.h"
#include "script_sound.h"
#include "script.h"
#include "unittype.h"
@ -93,6 +94,8 @@ static SpellActionType *CclSpellAction(lua_State *l)
spellaction = new Spell_SpawnPortal;
} else if (!strcmp(value, "summon")) {
spellaction = new Spell_Summon;
} else if (!strcmp(value, "teleport")) {
spellaction = new Spell_Teleport;
} else {
LuaError(l, "Unsupported action type: %s" _C_ value);
}

View file

@ -0,0 +1,75 @@
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
/**@name spell_teleport.cpp - The spell Teleport. */
//
// (c) Copyright 2013 by cybermind
//
// This program 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; only version 2 of the License.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//@{
#include "stratagus.h"
#include "spell/spell_teleport.h"
#include "game.h"
#include "map.h"
#include "script.h"
#include "unit.h"
/* virtual */ void Spell_Teleport::Parse(lua_State *l, int startIndex, int endIndex)
{
for (int j = startIndex; j < endIndex; ++j) {
lua_rawgeti(l, -1, j + 1);
const char *value = LuaToString(l, -1);
lua_pop(l, 1);
++j;
LuaError(l, "Unsupported Teleport tag: %s" _C_ value);
}
}
/**
** Cast teleport.
**
** @param caster Unit that casts the spell
** @param spell Spell-type pointer
** @param goalPos coord of target spot to cast
**
** @return =!0 if spell should be repeated, 0 if not
*/
/* virtual */ int Spell_Teleport::Cast(CUnit &caster, const SpellType &spell, CUnit * /*target*/, const Vec2i &goalPos)
{
if (Map.Info.IsPointOnMap(goalPos)) {
unsigned int selected = caster.Selected;
caster.Remove(NULL);
caster.tilePos = goalPos;
DropOutNearest(caster, goalPos, NULL);
if (selected) {
SelectUnit(caster);
}
}
return 0;
}
//@}

View file

@ -2073,9 +2073,9 @@ void DropOutNearest(CUnit &unit, const Vec2i &goalPos, const CUnit *container)
int bestd = 99999;
int addx = 0;
int addy = 0;
Assert(unit.Removed);
if (container) {
Assert(unit.Removed);
pos = container->tilePos;
pos.x -= unit.Type->TileWidth - 1;
pos.y -= unit.Type->TileHeight - 1;