1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-26 10:13:49 +00:00
Aquaria/files/scripts/entities/breakablecommon.lua

150 lines
3.4 KiB
Lua
Raw Normal View History

-- Copyright (C) 2007, 2010 - Bit-Blot
--
-- This file is part of Aquaria.
--
-- Aquaria is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2
-- of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
--
-- See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if not v then v = {} end
if not AQUARIA_VERSION then dofile("scripts/entities/entityinclude.lua") end
v.n = 0
v.file = ""
v.entToSpawn = ""
v.ingToSpawn = ""
v.amount = 0
v.breakSound = ""
v.spawnTimes = 1
v.sfxVol = 1
function v.commonInit(me, fle, cr, h, num, snd, ignoreSets, stimes, svol)
Fixed some script interface functions, error handling & code cleanups == Script interface changes: == Removed entity_setClampOnSwitchDir(), which was a no-op. Added entity_getFlag() function, for fairness, as nodes already have one. Added node_getLabel() function, which does not return the _full_ node string, but only the first part before parameters. dofile() supports relative paths now, and it is no longer necessary to use appendUserDataPath() + full path from a mod. entity_color() does now support all interpolation functions that similar vector-manipulation functions support (loop, ping-pong, ease). added entity_getVel() function (an entity_setVel() can be emulated with entity_clearVel(), followed by entity_addVel()). *_getNearestNode() and *_getNearestEntity() allow an optional ignore parameter. node_getNearestNode() allowed to specify a node to exclude from the search, the others not -- now the interface is more consistent. Deprecated entity_[incr/decr]TargetLeaches(entity) - the attached leach amount was never handled by any entity other than Naija. Replaced them with avatar_[incr/decr]Leaches(), but kept the old ames for now, too. Should be removed in a while. == Script interface & related fixes: == Added bool loudScriptErrors to control displaying script syntax error and global variable usage warnings. So far, syntax errors always went do debugLog(), but it is less time consuming when writing scripts to have them displayed right away. *_getNearestNode now scan by label, and not full name. This allows searching for nodes but ignoring its parameters. The original game scripts never search for nodes that have parameters, so this does not break anything, but allows modding without an exploding amount of specialized node scripts. entity_setBoneLock() failed for certain entites with throwLuaErrors=true, allowing to burst through them (gears, grouper, big mithalas jelly, probably more). Removed unnecessary int-casts in entity_setHealth(), entity_changeHealth(), and a few others, which truncated float fractional parts. Fixed possible crashes in many functions due to missing NULL-pointer checks, if wrong data were passed to Lua. Optimized entity_getNearestEntity() a little - do nocasecmp() after checking all other params UPPERCASE global variables as used in mod include files are now tolerated, even with all warnings on. This makes sense because it was impossible to include a custom flags definition file (which _must_ have globals, otherwise the including scripts won't see them) in a mod without beeing buried in spam. They won't change, or clobber any states, and UPPERCASE sort of implies a constant/#define, imho. Added better control over warnings about not-existing files. map_*.lua and premap_*.lua files are optional, and no warning should be given if they do not exist. Missing Entity scripts and mod-init.lua must be warned about, however. Fixed a crash in global variable access warning (NULL pushed into std::ostringstream) Fixed 2 random warnings i found in scrips == Misc stuff: == Related to the changes above, cleaned out unused variables from the Entity class, and removed the code that had to do with them somehow. Some parts of the removed code were still in use, although totally unnecessary. Saves a few bytes of memory per entity, and less code that can cause headache.
2011-09-18 21:12:02 +00:00
if svol and svol ~= 0 then
v.sfxVol = svol
end
setupEntity(me)
v.breakSound = snd
entity_setTexture(me, fle)
entity_setEntityType(me, ET_ENEMY)
entity_setCollideRadius(me, cr)
entity_setHealth(me, h)
entity_setDeathScene(me, true)
entity_setDeathSound(me, "")
v.file = fle
v.numSpawn = num
entity_setEatType(me, EAT_NONE)
entity_setState(me, STATE_IDLE)
entity_setUpdateCull(me, 3000)
if not ignoreSets then
local n1 = getNearestNodeByType(entity_x(me), entity_y(me), PATH_SETING)
if n1 ~= 0 and node_isEntityIn(n1, me) then
v.ingToSpawn = node_getContent(n1)
v.amount = node_getAmount(n1) if v.amount == 0 then v.amount = 1 end
else
local n2 = getNearestNodeByType(entity_x(me), entity_y(me), PATH_SETENT)
if n2 ~= 0 and node_isEntityIn(n2, me) then
v.entToSpawn = node_getContent(n2)
v.amount = node_getAmount(n2) if v.amount == 0 then v.amount = 1 end
end
end
end
esetv(me, EV_TYPEID, EVT_CONTAINER)
v.spawnTimes = stimes
end
function postInit(me)
v.n = getNaija()
entity_setTarget(me, v.n)
end
function update(me, dt)
entity_handleShotCollisions(me)
end
function enterState(me)
if entity_isState(me, STATE_IDLE) then
elseif entity_isState(me, STATE_DEAD) then
if v.ingToSpawn ~= "" or v.entToSpawn ~= "" then
playSfx("secret", 0, 0.7)
end
elseif entity_isState(me, STATE_DEATHSCENE) then
spawnParticleEffect("SmallBubbleExplosion", entity_getPosition(me))
for i=1,v.spawnTimes do
for i=1,v.numSpawn do
debugLog("Spawning")
local e = createEntity("BrokenPiece", "", entity_x(me), entity_y(me))
local str = string.format("%s-000%d", v.file, i)
--debugLog(str)
entity_setTexture(e, str)
end
end
entity_setStateTime(me, 0.1)
if v.ingToSpawn ~= "" then
for i=1,v.amount do
spawnIngredient(v.ingToSpawn, entity_x(me), entity_y(me))
end
elseif v.entToSpawn ~= "" then
for i=1,v.amount do
createEntity(v.entToSpawn, "", entity_x(me), entity_y(me))
end
end
entity_alpha(me, 0, 0.1)
entity_setStateTime(me, 0.1)
playSfx(v.breakSound, 0, v.sfxVol)
end
end
function exitState(me)
end
function damage(me, attacker, bone, damageType, dmg)
return true
end
function animationKey(me, key)
end
function hitSurface(me)
end
function songNote(me, note)
end
function songNoteDone(me, note)
end
function song(me, song)
end
function activate(me)
end