Thread: [Moeng-cvs] BBRpg/data/scripts AdvAIRandom.lua, 1.7, 1.8 Enemy.lua, 1.5, 1.6
Status: Alpha
Brought to you by:
b_lindeijer
From: Bjørn L. <b_l...@us...> - 2007-02-08 17:51:44
|
Update of /cvsroot/moeng/BBRpg/data/scripts In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv24515 Modified Files: AdvAIRandom.lua Enemy.lua Log Message: Added some sanity checks to prevent crashing and adapted three for loops to Lua 5.1. Probably a lot more will need fixing though. Index: Enemy.lua =================================================================== RCS file: /cvsroot/moeng/BBRpg/data/scripts/Enemy.lua,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Enemy.lua 1 Jan 2004 17:39:40 -0000 1.5 --- Enemy.lua 8 Feb 2007 17:51:38 -0000 1.6 *************** *** 1,81 **** ! ! import("Character.lua") ! ! ! Enemy = Character:subclass ! { ! name = "Enemy"; ! ! --== Commands ==-- ! ! attack = function(self) ! if (self.bAttacking == false and self.walking == 0 and self.charging == 0) then ! self:log("attacking.") ! self.bAttacking = true ! ! -- See if there is something at the attacked location ! local ax, ay = self.x, self.y ! if (self.dir == DIR_LEFT) then ax = ax - 1 end ! if (self.dir == DIR_RIGHT) then ax = ax + 1 end ! if (self.dir == DIR_UP) then ay = ay - 1 end ! if (self.dir == DIR_DOWN) then ay = ay + 1 end ! ! local attackedObjs = m_get_objects_at(ax, ay, self.map) ! local damage = self.attackMinDam + math.random(self.attackMaxDam - self.attackMinDam) ! ! -- Deal damage ! for index, object in attackedObjs do ! if (object:instanceOf(Actor)) then ! object:takeDamage(damage, self) ! end ! end ! ! -- Enable next attack after attackTime + chargeTime game ticks ! ActionController:addSequence{ ! ActionWait(self.attackTime), ! ActionSetVariable(self, "bAttacking", false), ! ActionSetVariable(self, "charging", self.chargeTime), ! } ! end ! end; ! ! ! --== Notifications ==-- ! ! died = function(self, killer, damageType, location) ! -- Let character adapt to dead status ! Character.died(self, killer, damageType, location) ! ! -- Give players experience ! if (killer and killer:instanceOf(Player)) then ! killer:gainExperience(self.experience) ! end ! ! -- Fade away ! ActionController:addSequence({ ! ActionWait(100), ! ActionSetVariable(self, "draw_mode", DM_TRANS), ! ActionTweenVariable(self, "alpha", 200, 0), ! ActionDestroyObject(self), ! }) ! ! -- Enemies don't need tick when dead ! self.tick_time = 0 ! end; ! ! ! defaultproperties = { ! experience = 0, ! attackTime = 50, ! chargeTime = 100, ! charging = 0, ! attackMinDam = 0, ! attackMaxDam = 5, ! ! bAttacking = false, ! ! deathBitmap = nil, ! ! controllerClass = AIController, ! }; ! } --- 1,81 ---- ! ! import("Character.lua") ! ! ! Enemy = Character:subclass ! { ! name = "Enemy"; ! ! --== Commands ==-- ! ! attack = function(self) ! if (self.bAttacking == false and self.walking == 0 and self.charging == 0) then ! self:log("attacking.") ! self.bAttacking = true ! ! -- See if there is something at the attacked location ! local ax, ay = self.x, self.y ! if (self.dir == DIR_LEFT) then ax = ax - 1 end ! if (self.dir == DIR_RIGHT) then ax = ax + 1 end ! if (self.dir == DIR_UP) then ay = ay - 1 end ! if (self.dir == DIR_DOWN) then ay = ay + 1 end ! ! local attackedObjs = m_get_objects_at(ax, ay, self.map) ! local damage = self.attackMinDam + math.random(self.attackMaxDam - self.attackMinDam) ! ! -- Deal damage ! for index, object in ipairs(attackedObjs) do ! if (object:instanceOf(Actor)) then ! object:takeDamage(damage, self) ! end ! end ! ! -- Enable next attack after attackTime + chargeTime game ticks ! ActionController:addSequence{ ! ActionWait(self.attackTime), ! ActionSetVariable(self, "bAttacking", false), ! ActionSetVariable(self, "charging", self.chargeTime), ! } ! end ! end; ! ! ! --== Notifications ==-- ! ! died = function(self, killer, damageType, location) ! -- Let character adapt to dead status ! Character.died(self, killer, damageType, location) ! ! -- Give players experience ! if (killer and killer:instanceOf(Player)) then ! killer:gainExperience(self.experience) ! end ! ! -- Fade away ! ActionController:addSequence({ ! ActionWait(100), ! ActionSetVariable(self, "draw_mode", DM_TRANS), ! ActionTweenVariable(self, "alpha", 200, 0), ! ActionDestroyObject(self), ! }) ! ! -- Enemies don't need tick when dead ! self.tick_time = 0 ! end; ! ! ! defaultproperties = { ! experience = 0, ! attackTime = 50, ! chargeTime = 100, ! charging = 0, ! attackMinDam = 0, ! attackMaxDam = 5, ! ! bAttacking = false, ! ! deathBitmap = nil, ! ! controllerClass = AIController, ! }; ! } Index: AdvAIRandom.lua =================================================================== RCS file: /cvsroot/moeng/BBRpg/data/scripts/AdvAIRandom.lua,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** AdvAIRandom.lua 13 Jan 2004 16:32:35 -0000 1.7 --- AdvAIRandom.lua 8 Feb 2007 17:51:38 -0000 1.8 *************** *** 77,86 **** goingDirection = function(self, dir, notdir) local dirs = self.pawn:freeTilesAround() ! for v in dirs do if (v == dir) then return dir end; end; ! for v in dirs do if (v ~= notdir) then return v; --- 77,86 ---- goingDirection = function(self, dir, notdir) local dirs = self.pawn:freeTilesAround() ! for k,v in pairs(dirs) do if (v == dir) then return dir end; end; ! for k,v in pairs(dirs) do if (v ~= notdir) then return v; |