00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <actions/ExplosionParams.h>
00022 #include <lua/LUAUtil.h>
00023 #include <XML/XMLNode.h>
00024
00025 ExplosionParams::ExplosionParams() :
00026 size_(1),
00027 multiColored_(false), hurtAmount_(0),
00028 deform_(DeformDown),
00029 createDebris_(true), createMushroomAmount_(0),
00030 createSplash_(true), windAffected_(true),
00031 luminance_(true), animate_(true),
00032 onlyHurtShield_(false), explodeUnderGround_(true),
00033 minLife_(true, 5000), maxLife_(1), shake_(0),
00034 explosionTexture_("exp00")
00035 {
00036 }
00037
00038 ExplosionParams::~ExplosionParams()
00039 {
00040 }
00041
00042 const char *ExplosionParams::getExplosionTexture()
00043 {
00044 return explosionTexture_.c_str();
00045 }
00046
00047 const char *ExplosionParams::getExplosionSound()
00048 {
00049 if (!explosionSound_.c_str()[0]) return 0;
00050 return explosionSound_.c_str();
00051 }
00052
00053 FixedVector &ExplosionParams::getExplosionColor()
00054 {
00055 static FixedVector white(1, 1, 1);
00056 if (!multiColored_) return white;
00057
00058 static FixedVector red(1, 0, 0);
00059 static FixedVector green(0, 1, 0);
00060 static FixedVector blue(0, 0, 1);
00061 static FixedVector yellow(1, 1, 0);
00062
00063 int color = int(RAND * 4.0f);
00064 switch (color)
00065 {
00066 case 0:
00067 return red;
00068 case 1:
00069 return green;
00070 case 2:
00071 return blue;
00072 case 3:
00073 return yellow;
00074 }
00075 return white;
00076 }
00077
00078 bool ExplosionParams::parseXML(XMLNode *accessoryNode)
00079 {
00080
00081 XMLNode *colorNode = 0;
00082 accessoryNode->getNamedChild("multicolor", colorNode, false);
00083 if (colorNode) multiColored_ = true;
00084
00085
00086 accessoryNode->getNamedChild("onlyhurtshield", onlyHurtShield_, false);
00087
00088 accessoryNode->getNamedChild("explodeunderground", explodeUnderGround_, false);
00089
00090
00091 XMLNode *noCreateDebrisNode = 0;
00092 accessoryNode->getNamedChild("nocreatedebris", noCreateDebrisNode, false);
00093 if (noCreateDebrisNode) createDebris_ = false;
00094
00095
00096 XMLNode *noCreateSplashNode = 0;
00097 accessoryNode->getNamedChild("nocreatesplash", noCreateSplashNode, false);
00098 if (noCreateSplashNode) createSplash_ = false;
00099
00100
00101 XMLNode *noWindAffectedNode = 0;
00102 accessoryNode->getNamedChild("nowindaffected", noWindAffectedNode, false);
00103 if (noWindAffectedNode) windAffected_ = false;
00104
00105
00106 XMLNode *noLuminanceNode = 0;
00107 accessoryNode->getNamedChild("noluminance", noLuminanceNode, false);
00108 if (noLuminanceNode) luminance_ = false;
00109
00110
00111 XMLNode *animateNode = 0;
00112 accessoryNode->getNamedChild("animate", animateNode, false);
00113 if (animateNode) animate_ = true;
00114 XMLNode *noAnimateNode = 0;
00115 accessoryNode->getNamedChild("noanimate", noAnimateNode, false);
00116 if (noAnimateNode) animate_ = false;
00117
00118
00119 if (accessoryNode->getNamedChild("deformtexture", deformTexture_, false))
00120 {
00121 if (!S3D::checkDataFile(getDeformTexture())) return false;
00122 }
00123
00124
00125 accessoryNode->getNamedChild("explosiontexture", explosionTexture_, false);
00126
00127
00128 if (accessoryNode->getNamedChild("explosionsound", explosionSound_, false))
00129 {
00130 if (!S3D::checkDataFile(S3D::formatStringBuffer("data/wav/%s", getExplosionSound()))) return false;
00131 }
00132
00133
00134 XMLNode *deformNode = 0;
00135 if (!accessoryNode->getNamedChild("deform", deformNode)) return false;
00136 if (0 == strcmp(deformNode->getContent(), "down")) deform_ = DeformDown;
00137 else if (0 == strcmp(deformNode->getContent(), "up")) deform_ = DeformUp;
00138 else if (0 == strcmp(deformNode->getContent(), "none")) deform_ = DeformNone;
00139 else return deformNode->returnError(
00140 S3D::formatStringBuffer("Unknown deform type \"%s\" should be up, down or none",
00141 deformNode->getContent()));
00142
00143 return true;
00144 }
00145
00146 void ExplosionParams::parseLUA(lua_State *L, int position)
00147 {
00148 luaL_checktype(L, position, LUA_TTABLE);
00149
00150 size_ = LUAUtil::getNumberFromTable(L, position, "size", size_);
00151 hurtAmount_ = LUAUtil::getNumberFromTable(L, position, "hurtamount", hurtAmount_);
00152
00153 shake_ = LUAUtil::getNumberFromTable(L, position, "shake", shake_);
00154 minLife_ = LUAUtil::getNumberFromTable(L, position, "minlife", minLife_);
00155 maxLife_ = LUAUtil::getNumberFromTable(L, position, "maxlife", maxLife_);
00156 createMushroomAmount_ = LUAUtil::getNumberFromTable(L, position, "createmushroomamount", createMushroomAmount_);
00157
00158 luminance_ = LUAUtil::getBoolFromTable(L, position, "luminance", luminance_);
00159 windAffected_ = LUAUtil::getBoolFromTable(L, position, "windaffected", windAffected_);
00160 multiColored_ = LUAUtil::getBoolFromTable(L, position, "multicolored", multiColored_);
00161 createDebris_ = LUAUtil::getBoolFromTable(L, position, "createdebris", createDebris_);
00162 createSplash_ = LUAUtil::getBoolFromTable(L, position, "createsplash", createSplash_);
00163 explodeUnderGround_ = LUAUtil::getBoolFromTable(L, position, "explodeunderground", explodeUnderGround_);
00164 onlyHurtShield_ = LUAUtil::getBoolFromTable(L, position, "onlyhurtshield", onlyHurtShield_);
00165 animate_ = LUAUtil::getBoolFromTable(L, position, "animate", animate_);
00166
00167 deformTexture_ = LUAUtil::getStringFromTable(L, position, "deformtexture", deformTexture_);
00168 explosionTexture_ = LUAUtil::getStringFromTable(L, position, "explosiontexture", explosionTexture_);
00169 explosionSound_ = LUAUtil::getStringFromTable(L, position, "explosionsound", explosionSound_);
00170
00171 fixed deform = LUAUtil::getNumberFromTable(L, position, "deform", int(deform_));
00172 deform_ = (DeformType) deform.asInt();
00173 }