From 36247593d4fc568dd2a56f8923fb9800ead4b769 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 16 May 2013 03:54:20 +0200 Subject: [PATCH 1/2] Fix possible crash due to unsafe shot iteration. Fixes regression introduced in 0784d1b9dff. With a std::list it was okay to create shots while iterating with an iterator, but not so with a std::vector. Now using index access, which is safe with push_back() operations. --- Aquaria/Game.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 733399b..1f44e86 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -8402,9 +8402,9 @@ void Game::handleShotCollisions(Entity *e, bool hasShield) { BBGE_PROF(Game_handleShotCollisions); bool isRegValid=true; - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot) && (!hasShield || (!shot->shotData || !shot->shotData->ignoreShield))) { Vector collidePoint = e->position+e->offset; @@ -8434,9 +8434,9 @@ bool Game::isDamageTypeEnemy(DamageType dt) void Game::handleShotCollisionsSkeletal(Entity *e) { BBGE_PROF(Game_HSSKELETAL); - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot)) { Bone *b = collideSkeletalVsCircle(e, shot->position, shot->collideRadius); @@ -8451,9 +8451,9 @@ void Game::handleShotCollisionsSkeletal(Entity *e) void Game::handleShotCollisionsHair(Entity *e, int num) { - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot)) { bool b = collideHairVsCircle(e, num, shot->position, 8); From f7740eb6e8f163e9ce748c7ba4b543a321cb65c8 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 19 May 2013 20:14:00 +0200 Subject: [PATCH 2/2] add beam_setDamageType() Lua function --- Aquaria/ScriptInterface.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index c4517ea..5f53ff2 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3746,6 +3746,16 @@ luaFunc(beam_setDamage) luaReturnNil(); } +luaFunc(beam_setDamageType) +{ + Beam *b = beam(L); + if (b) + { + b->damageData.damageType = (DamageType)lua_tointeger(L, 2); + } + luaReturnNil(); +} + luaFunc(beam_setBeamWidth) { Beam *b = beam(L); @@ -7950,6 +7960,7 @@ static const struct { luaRegister(beam_setDamage), luaRegister(beam_setBeamWidth), luaRegister(beam_setFirer), + luaRegister(beam_setDamageType), luaRegister(getStringBank),