____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

spells.cpp File Reference

The spell cast action. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include "unittype.h"
#include "unit_cache.h"
#include "spells.h"
#include "sound.h"
#include "missile.h"
#include "map.h"
#include "ui.h"
#include "actions.h"

Go to the source code of this file.

Functions

static void EvaluateMissileLocation (const SpellActionMissileLocation *location, CUnit *caster, CUnit *target, int x, int y, int *resx, int *resy)
static TargetNewTargetUnit (CUnit *unit)
static bool PassCondition (const CUnit *caster, const SpellType *spell, const CUnit *target, int x, int y, const ConditionInfo *condition)
static TargetSelectTargetUnitsOfAutoCast (CUnit *caster, const SpellType *spell)
void InitSpells (void)
 done spell tables
SpellTypeSpellTypeByIdent (const std::string &ident)
 return 0, 1, 2 for true, only, false.
bool SpellIsAvailable (const CPlayer *player, int spellid)
 returns true if spell can be casted (enough mana, valid target)
bool CanCastSpell (const CUnit *caster, const SpellType *spell, const CUnit *target, int x, int y)
 cast spell on target unit or place at x,y
int AutoCastSpell (CUnit *caster, const SpellType *spell)
 return spell type by ident string
int SpellCast (CUnit *caster, const SpellType *spell, CUnit *target, int x, int y)
 auto cast the spell if possible
void CleanSpells (void)
 return 1 if spell is availible, 0 if not (must upgrade)

Variables

std::vector< SpellType * > SpellTypeTable


Detailed Description

The spell cast action.

Definition in file spells.cpp.


Function Documentation

int AutoCastSpell ( CUnit caster,
const SpellType spell 
)

return spell type by ident string

Check if the spell can be auto cast and cast it.

Parameters:
caster Unit who can cast the spell.
spell Spell-type pointer.
Returns:
1 if spell is casted, 0 if not.

Definition at line 1036 of file spells.cpp.

References CommandSpellCast(), FlushCommands, MANA_INDEX, SpellType::ManaCost, CUnit::Player, SelectTargetUnitsOfAutoCast(), SpellType::Slot, SpellIsAvailable(), Target::Unit, CVariable::Value, CUnit::Variable, Target::X, and Target::Y.

Referenced by AiCheckMagic(), AutoCast(), CButtonPanel::DoClicked(), GetButtonStatus(), and CUnit::Init().

bool CanCastSpell ( const CUnit caster,
const SpellType spell,
const CUnit target,
int  x,
int  y 
)

cast spell on target unit or place at x,y

Check if unit can cast the spell.

Parameters:
caster Unit that casts the spell
spell Spell-type pointer
target Target unit that spell is addressed to
x X coord of target spot when/if target does not exist
y Y coord of target spot when/if target does not exist
Returns:
=!0 if spell should/can casted, 0 if not
Note:
caster must know the spell, and spell must be available.

Definition at line 1019 of file spells.cpp.

References SpellType::Condition, PassCondition(), SpellType::Target, and TargetUnit.

Referenced by AreaAdjustVitals::Cast(), CclDefineSpell(), HandleActionSpellCast(), and SpellCast().

void CleanSpells ( void   ) 

return 1 if spell is availible, 0 if not (must upgrade)

Cleanup the spell subsystem.

Definition at line 1157 of file spells.cpp.

References DebugPrint, and SpellTypeTable.

Referenced by CleanModules().

static void EvaluateMissileLocation ( const SpellActionMissileLocation location,
CUnit caster,
CUnit target,
int  x,
int  y,
int *  resx,
int *  resy 
) [static]

Evaluate missile location description.

Parameters:
location Parameters for location.
caster Unit that casts the spell
target Target unit that spell is addressed to
x X coord of target spot when/if target does not exist
y Y coord of target spot when/if target does not exist
resx pointer to X coord of the result
resy pointer to Y coord of the result

Definition at line 303 of file spells.cpp.

References SpellActionMissileLocation::AddRandX, SpellActionMissileLocation::AddRandY, SpellActionMissileLocation::AddX, SpellActionMissileLocation::AddY, SpellActionMissileLocation::Base, LocBaseCaster, SyncRand(), TileSizeX, TileSizeY, CUnit::X, and CUnit::Y.

Referenced by SpawnMissile::Cast().

void InitSpells ( void   ) 

done spell tables

Spells constructor, inits spell id's and sounds

Definition at line 967 of file spells.cpp.

Referenced by CreateGame(), and InitModules().

static Target* NewTargetUnit ( CUnit unit  )  [static]

Target constructor for unit.

Parameters:
unit Target unit.
Returns:
the new target.

Definition at line 710 of file spells.cpp.

References TargetUnit.

Referenced by SelectTargetUnitsOfAutoCast().

static bool PassCondition ( const CUnit caster,
const SpellType spell,
const CUnit target,
int  x,
int  y,
const ConditionInfo condition 
) [static]

static Target* SelectTargetUnitsOfAutoCast ( CUnit caster,
const SpellType spell 
) [static]

Select the target for the autocast.

Parameters:
caster Unit who would cast the spell.
spell Spell-type pointer.
Returns:
Target* chosen target or Null if spell can't be cast.
Todo:
FIXME: should be global (for AI) ???
Todo:
FIXME: write for position target.

Definition at line 846 of file spells.cpp.

References SpellType::AICast, CPlayer::AiEnabled, Assert, SpellType::AutoCast, AutoCastInfo::Combat, AutoCastInfo::Condition, SpellType::Condition, CONDITION_ONLY, CONDITION_TRUE, CUnitType::Coward, DebugPrint, CUnit::IsEnemy(), NewTargetUnit(), PassCondition(), CUnit::Player, AutoCastInfo::Range, CUnitCache::Select(), SyncRand(), SpellType::Target, TargetPosition, TargetSelf, TargetUnit, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitCache, UnitMax, CUnit::X, CUnit::Y, and y.

Referenced by AutoCastSpell().

int SpellCast ( CUnit caster,
const SpellType spell,
CUnit target,
int  x,
int  y 
)

auto cast the spell if possible

Spell cast!

Parameters:
caster Unit that casts the spell
spell Spell-type pointer
target Target unit that spell is addressed to
x X coord of target spot when/if target does not exist
y Y coord of target spot when/if target does not exist
Returns:
!=0 if spell should/can continue or 0 to stop

Definition at line 1069 of file spells.cpp.

References _C_, SpellType::Action, CanCastSpell(), DebugPrint, SpellType::Ident, MANA_INDEX, SpellType::ManaCost, MaxSampleVolume, CUnitType::Name, PlayGameSound(), SpellType::RepeatCast, SoundConfig::Sound, SpellType::SoundWhenCast, SpellType::Target, TargetSelf, CUnit::Type, CVariable::Value, CUnit::Variable, CUnit::X, and CUnit::Y.

Referenced by HandleActionSpellCast(), and UnitShowAnimationScaled().

bool SpellIsAvailable ( const CPlayer player,
int  spellid 
)

returns true if spell can be casted (enough mana, valid target)

Check if spell is available for player player.

Parameters:
player player for who we want to know if he knows the spell.
spellid id of the spell to check.
Returns:
0 if spell is not available, else no null.

Definition at line 999 of file spells.cpp.

References SpellTypeTable.

Referenced by AiCheckMagic(), AutoCastSpell(), and IsButtonAllowed().

SpellType* SpellTypeByIdent ( const std::string &  ident  ) 

return 0, 1, 2 for true, only, false.

Get spell-type struct pointer by string identifier.

Parameters:
ident Spell identifier.
Returns:
spell-type struct pointer.

Definition at line 978 of file spells.cpp.

References SpellTypeTable.

Referenced by AddButton(), CclDefineSpell(), CclDefineUnitType(), CclParseOrder(), and CclUnit().


Variable Documentation

std::vector<SpellType*> SpellTypeTable


Generated on Sat Feb 21 00:28:19 2009 for Bos Wars by  doxygen 1.5.6