afxRPGMagicSpell.cpp
Engine/source/afx/rpg/afxRPGMagicSpell.cpp
Public Defines
define
BR() "\n"
define
CASTLEN_FMT() "<just:left><font:Arial:16><color:FFFFFF>"
define
DESC_FMT() "<just:left><font:Arial:16><color:ACACAC>"
define
MANACOST_FMT() "<just:left><font:Arial:16><color:FFFFFF>"
define
myOffset(field) (field, )
define
NAME_FMT() "<just:left><font:Arial:20><color:FFD200>"
define
PACK_FMT() "<just:right><font:Arial:14><color:ACACAC>"
define
PACK_NAME_FMT() "<color:FFD200>"
define
RANGE_FMT() "<just:right><font:Arial:16><color:FFFFFF>"
define
SMALL_BR() "<font:Arial:4>\"
define
TARGET_FMT() "<just:right><font:Arial:20><color:ACACAC>"
Public Variables
Public Functions
ConsoleDocClass(afxRPGMagicSpellData , "@brief A datablock <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> defining RPG aspects of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">spell.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxMisc\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
ImplementEnumType(afxRPGMagicSpell_TargetType , "Possible RPG spell target <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxRPGMagicSpell\n\n</a>" )
Detailed Description
Public Defines
BR() "\n"
CASTLEN_FMT() "<just:left><font:Arial:16><color:FFFFFF>"
DESC_FMT() "<just:left><font:Arial:16><color:ACACAC>"
MANACOST_FMT() "<just:left><font:Arial:16><color:FFFFFF>"
myOffset(field) (field, )
NAME_FMT() "<just:left><font:Arial:20><color:FFD200>"
PACK_FMT() "<just:right><font:Arial:14><color:ACACAC>"
PACK_NAME_FMT() "<color:FFD200>"
RANGE_FMT() "<just:right><font:Arial:16><color:FFFFFF>"
SMALL_BR() "<font:Arial:4>\"
TARGET_FMT() "<just:right><font:Arial:20><color:ACACAC>"
Public Variables
EndImplementEnumType
Public Functions
ConsoleDocClass(afxRPGMagicSpellData , "@brief A datablock <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> defining RPG aspects of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">spell.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxMisc\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
IMPLEMENT_CO_DATABLOCK_V1(afxRPGMagicSpellData )
ImplementEnumType(afxRPGMagicSpell_TargetType , "Possible RPG spell target <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxRPGMagicSpell\n\n</a>" )
1 2 3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 5// Copyright (C) 2015 Faust Logic, Inc. 6// 7// Permission is hereby granted, free of charge, to any person obtaining a copy 8// of this software and associated documentation files (the "Software"), to 9// deal in the Software without restriction, including without limitation the 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11// sell copies of the Software, and to permit persons to whom the Software is 12// furnished to do so, subject to the following conditions: 13// 14// The above copyright notice and this permission notice shall be included in 15// all copies or substantial portions of the Software. 16// 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23// IN THE SOFTWARE. 24// 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 26 27#include "afx/arcaneFX.h" 28#include "afxRPGMagicSpell.h" 29 30//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 31// afxRPGMagicSpellData 32 33IMPLEMENT_CO_DATABLOCK_V1(afxRPGMagicSpellData); 34 35ConsoleDocClass( afxRPGMagicSpellData, 36 "@brief A datablock for defining RPG aspects of a spell.\n\n" 37 38 "@ingroup afxMisc\n" 39 "@ingroup AFX\n" 40 "@ingroup Datablocks\n" 41); 42 43afxRPGMagicSpellData::afxRPGMagicSpellData() 44{ 45 // spell parameters 46 spell_name = ST_NULLSTRING; 47 spell_desc = ST_NULLSTRING; 48 spell_target = TARGET_NOTHING; 49 spell_range = 0.0f; 50 mana_cost = 0; 51 52 n_reagents = 0; 53 for (S32 i = 0; i < MAX_REAGENTS_PER_SPELL; i++) 54 { 55 reagent_cost[i] = 1; 56 reagent_name[i] = ST_NULLSTRING; 57 } 58 59 // spell phase timing 60 casting_dur = 0.0f; 61 62 // interface elements 63 icon_name = ST_NULLSTRING; 64 source_pack = ST_NULLSTRING; 65 66 is_placeholder = false; 67 68 free_target_style = 0; 69 target_optional = false; 70} 71 72ImplementEnumType( afxRPGMagicSpell_TargetType, "Possible RPG spell target types.\n" "@ingroup afxRPGMagicSpell\n\n" ) 73 { afxRPGMagicSpellData::TARGET_NOTHING, "nothing", "..." }, 74 { afxRPGMagicSpellData::TARGET_SELF, "self", "..." }, 75 { afxRPGMagicSpellData::TARGET_FRIEND, "friend", "..." }, 76 { afxRPGMagicSpellData::TARGET_ENEMY, "enemy", "..." }, 77 { afxRPGMagicSpellData::TARGET_CORPSE, "corpse", "..." }, 78 { afxRPGMagicSpellData::TARGET_FREE, "free", "..." }, 79EndImplementEnumType; 80 81#define myOffset(field) Offset(field, afxRPGMagicSpellData) 82 83void afxRPGMagicSpellData::initPersistFields() 84{ 85 // spell parameters 86 addField("spellName", TypeString, myOffset(spell_name), 87 "..."); 88 addField("desc", TypeString, myOffset(spell_desc), 89 "..."); 90 91 addField("target", TYPEID< afxRPGMagicSpellData::TargetType >(), myOffset(spell_target), 92 "..."); 93 94 addField("range", TypeF32, myOffset(spell_range), 95 "..."); 96 addField("manaCost", TypeS32, myOffset(mana_cost), 97 "..."); 98 addField("reagentCost", TypeS8, myOffset(reagent_cost), MAX_REAGENTS_PER_SPELL, 99 "..."); 100 addField("reagentName", TypeString, myOffset(reagent_name), MAX_REAGENTS_PER_SPELL, 101 "..."); 102 103 // spell phase timing 104 addField("castingDur", TypeF32, myOffset(casting_dur)); 105 106 // interface elements 107 addField("iconBitmap", TypeFilename, myOffset(icon_name)); 108 addField("sourcePack", TypeString, myOffset(source_pack)); 109 addField("isPlaceholder", TypeBool, myOffset(is_placeholder)); 110 addField("freeTargetStyle", TypeS8, myOffset(free_target_style)); 111 addField("targetOptional", TypeBool, myOffset(target_optional)); 112 113 Parent::initPersistFields(); 114} 115 116bool afxRPGMagicSpellData::onAdd() 117{ 118 if (Parent::onAdd() == false) 119 return false; 120 121 n_reagents = 0; 122 for (S32 i = 0; i < MAX_REAGENTS_PER_SPELL && reagent_name[i] != ST_NULLSTRING; i++) 123 n_reagents++; 124 125 return true; 126} 127 128void afxRPGMagicSpellData::packData(BitStream* stream) 129{ 130 Parent::packData(stream); 131 132 stream->write(spell_target); 133 stream->write(spell_range); 134 stream->write(mana_cost); 135 stream->write(n_reagents); 136 for (S32 i = 0; i < n_reagents; i++) 137 { 138 stream->write(reagent_cost[i]); 139 stream->writeString(reagent_name[i]); 140 } 141 142 stream->write(casting_dur); 143 144 stream->writeString(spell_name); 145 stream->writeLongString(511, spell_desc); 146 stream->writeString(icon_name); 147 stream->writeString(source_pack); 148 stream->writeFlag(is_placeholder); 149 stream->writeFlag(target_optional); 150 stream->write(free_target_style); 151} 152 153void afxRPGMagicSpellData::unpackData(BitStream* stream) 154{ 155 Parent::unpackData(stream); 156 157 stream->read(&spell_target); 158 stream->read(&spell_range); 159 stream->read(&mana_cost); 160 stream->read(&n_reagents); 161 for (S32 i = 0; i < n_reagents; i++) 162 { 163 stream->read(&reagent_cost[i]); 164 reagent_name[i] = stream->readSTString(); 165 } 166 167 stream->read(&casting_dur); 168 169 spell_name = stream->readSTString(); 170 { 171 char value[512]; 172 stream->readLongString(511, value); 173 spell_desc = StringTable->insert(value); 174 } 175 icon_name = stream->readSTString(); 176 source_pack = stream->readSTString(); 177 is_placeholder = stream->readFlag(); 178 target_optional = stream->readFlag(); 179 stream->read(&free_target_style); 180} 181 182#define NAME_FMT "<just:left><font:Arial:20><color:FFD200>" 183#define TARGET_FMT "<just:right><font:Arial:20><color:ACACAC>" 184#define MANACOST_FMT "<just:left><font:Arial:16><color:FFFFFF>" 185#define RANGE_FMT "<just:right><font:Arial:16><color:FFFFFF>" 186#define CASTLEN_FMT "<just:left><font:Arial:16><color:FFFFFF>" 187#define DESC_FMT "<just:left><font:Arial:16><color:ACACAC>" 188#define SMALL_BR "<font:Arial:4>\n" 189#define BR "\n" 190#define PACK_FMT "<just:right><font:Arial:14><color:ACACAC>" 191#define PACK_NAME_FMT "<color:FFD200>" 192 193 194char* afxRPGMagicSpellData::fmt_placeholder_desc(char* buffer, int len) const 195{ 196 char pack_str[32]; 197 if (source_pack == ST_NULLSTRING) 198 dStrcpy(pack_str, "unknown", 32); 199 else 200 dSprintf(pack_str, 32, "%s", source_pack); 201 202 dSprintf(buffer, len, 203 NAME_FMT "%s" BR 204 SMALL_BR 205 DESC_FMT "%s" BR 206 SMALL_BR SMALL_BR 207 PACK_FMT "source: " PACK_NAME_FMT "%s", 208 spell_name, spell_desc, pack_str); 209 210 return buffer; 211} 212 213char* afxRPGMagicSpellData::formatDesc(char* buffer, int len) const 214{ 215 if (is_placeholder) 216 return fmt_placeholder_desc(buffer, len); 217 218 char target_str[32]; target_str[0] = '\0'; 219 220 // CAUTION: The following block of code is fragile and tricky since it depends 221 // on the underlying structures defined by ImplementEnumType/EndImplementEnumType. 222 // This done so the enum strings can be used directly in the spell description text. 223 for (unsigned int i = 0; i < _afxRPGMagicSpell_TargetType::_sEnumTable.getNumValues(); i++) 224 { 225 if (_afxRPGMagicSpell_TargetType::_sEnumTable[i].mInt == spell_target) 226 { 227 if (spell_target != TARGET_NOTHING) 228 { 229 dStrcpy(target_str, _afxRPGMagicSpell_TargetType::_sEnumTable[i].mName, 32); 230 if (spell_target != TARGET_FREE && target_optional) 231 dStrcat(target_str, " (opt)", 32); 232 } 233 break; 234 } 235 } 236 237 238 char range_str[32]; range_str[0] = '\0'; 239 if (spell_range > 0) 240 { 241 if (spell_range == ((F32)((S32)spell_range))) 242 dSprintf(range_str, 32, "%d meter range", (S32) spell_range); 243 else 244 dSprintf(range_str, 32, "%.1f meter range", spell_range); 245 } 246 247 char casting_str[32]; 248 if (casting_dur <= 0) 249 dStrcpy(casting_str, "instant", 32); 250 else 251 dSprintf(casting_str, 32, "%.1f sec cast", casting_dur); 252 253 char pack_str[32]; 254 if (source_pack == ST_NULLSTRING) 255 dStrcpy(pack_str, "unknown", 32); 256 else 257 dSprintf(pack_str, 32, "%s", source_pack); 258 259 dSprintf(buffer, len, 260 NAME_FMT "%s" TARGET_FMT "%s" BR 261 SMALL_BR 262 MANACOST_FMT "%d Mana" RANGE_FMT "%s" BR 263 CASTLEN_FMT "%s" BR 264 SMALL_BR SMALL_BR 265 DESC_FMT "%s" BR SMALL_BR 266 PACK_FMT "source: " PACK_NAME_FMT "%s", 267 spell_name, target_str, 268 mana_cost, range_str, 269 casting_str, 270 spell_desc, pack_str); 271 272 return buffer; 273} 274 275//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 276