2021-12-26 21:19:38 +01:00
/* ScummVM - Graphic Adventure Engine
2012-02-15 19:03:30 -08:00
*
2021-12-26 21:19:38 +01:00
* ScummVM is the legal property of its developers , whose names
2012-02-15 19:03:30 -08:00
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
*
2021-12-26 18:47:58 +01:00
* This program 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 3 of the License , or
* ( at your option ) any later version .
2014-04-05 18:18:42 +02:00
*
2012-12-19 23:15:43 +01:00
* This program is distributed in the hope that it will be useful ,
2012-02-15 19:03:30 -08:00
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
2012-12-19 23:15:43 +01:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
2014-04-05 18:18:42 +02:00
*
2012-12-19 23:15:43 +01:00
* You should have received a copy of the GNU General Public License
2021-12-26 18:47:58 +01:00
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
2012-02-15 19:03:30 -08:00
*
*/
2014-10-11 12:36:42 +02:00
# include "common/debug-channels.h"
2012-02-15 19:03:30 -08:00
# include "engines/grim/emi/lua_v2.h"
# include "engines/grim/lua/lua.h"
# include "engines/grim/actor.h"
2014-10-11 12:36:42 +02:00
# include "engines/grim/debug.h"
2012-05-06 10:00:48 -07:00
# include "engines/grim/grim.h"
2012-02-15 19:03:30 -08:00
# include "engines/grim/costume.h"
2014-07-27 21:24:10 +03:00
# include "engines/grim/set.h"
2013-07-14 10:16:27 -07:00
# include "engines/grim/emi/emi.h"
2012-03-11 14:36:14 +01:00
# include "engines/grim/emi/costumeemi.h"
# include "engines/grim/emi/skeleton.h"
2013-12-07 13:06:39 +01:00
# include "engines/grim/emi/costume/emichore.h"
2012-03-11 14:36:14 +01:00
# include "engines/grim/emi/costume/emiskel_component.h"
2014-07-27 21:24:10 +03:00
# include "engines/grim/lua/lauxlib.h"
2012-02-15 19:03:30 -08:00
namespace Grim {
void Lua_V2 : : SetActorLocalAlpha ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
2014-08-20 01:49:56 +02:00
lua_Object vertexObj = lua_getparam ( 2 ) ;
lua_Object alphaObj = lua_getparam ( 3 ) ;
2022-06-08 01:12:00 +02:00
//lua_Object unknownObj = lua_getparam(4);
2012-02-15 19:03:30 -08:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2014-08-20 01:49:56 +02:00
if ( ! lua_isnumber ( vertexObj ) )
return ;
if ( ! lua_isnumber ( alphaObj ) )
return ;
int vertex = lua_getnumber ( vertexObj ) ;
float alpha = lua_getnumber ( alphaObj ) ;
2014-09-08 18:30:22 -07:00
Actor : : AlphaMode mode = ( Actor : : AlphaMode ) ( int ) alpha ;
if ( mode = = Actor : : AlphaOff | | mode = = Actor : : AlphaReplace | | mode = = Actor : : AlphaModulate ) {
actor - > setLocalAlphaMode ( vertex , mode ) ;
2014-08-20 01:49:56 +02:00
} else {
actor - > setLocalAlpha ( vertex , alpha ) ;
}
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : SetActorGlobalAlpha ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
2012-04-07 23:53:27 +02:00
lua_Object alphaObj = lua_getparam ( 2 ) ;
2015-02-12 22:33:07 +01:00
lua_Object meshObj = lua_getparam ( 3 ) ;
2012-02-15 19:03:30 -08:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2012-04-07 23:53:27 +02:00
if ( ! lua_isnumber ( alphaObj ) )
2013-07-09 21:12:55 +02:00
return ;
2012-04-07 23:53:27 +02:00
2015-02-12 22:33:07 +01:00
const char * mesh = nullptr ;
if ( lua_isstring ( meshObj ) ) {
mesh = lua_getstring ( meshObj ) ;
}
2012-04-07 23:53:27 +02:00
float alpha = lua_getnumber ( alphaObj ) ;
2022-06-08 01:12:00 +02:00
if ( alpha = = Actor : : AlphaOff | | alpha = = Actor : : AlphaReplace | | alpha = = Actor : : AlphaModulate ) {
actor - > setAlphaMode ( ( Actor : : AlphaMode ) ( int ) alpha , mesh ) ;
2012-04-07 23:53:27 +02:00
} else {
2015-02-12 22:33:07 +01:00
actor - > setGlobalAlpha ( alpha , mesh ) ;
2012-02-15 19:03:30 -08:00
}
}
2012-03-25 16:47:22 -07:00
void Lua_V2 : : PutActorInOverworld ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
actor - > setInOverworld ( true ) ;
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : RemoveActorFromOverworld ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2012-03-25 16:47:22 -07:00
actor - > setInOverworld ( false ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : UnloadActor ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2012-05-06 10:00:48 -07:00
g_grim - > invalidateActiveActorsList ( ) ;
2012-08-07 00:21:27 +02:00
g_grim - > immediatelyRemoveActor ( actor ) ;
2013-05-21 23:25:36 +02:00
delete actor ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : SetActorWalkRate ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object rateObj = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
if ( ! lua_isnumber ( rateObj ) )
return ;
Actor * actor = getactor ( actorObj ) ;
float rate = lua_getnumber ( rateObj ) ;
// const below only differ from grim
actor - > setWalkRate ( rate * 3.279999971389771 ) ;
}
void Lua_V2 : : GetActorWalkRate ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
// const below only differ from grim
lua_pushnumber ( actor - > getWalkRate ( ) * 0.3048780560493469 ) ;
}
2013-11-26 21:04:55 +01:00
void Lua_V2 : : SetActorTurnRate ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object rateObj = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
if ( ! lua_isnumber ( rateObj ) )
return ;
Actor * actor = getactor ( actorObj ) ;
float rate = lua_getnumber ( rateObj ) ; // FIXME verify negate values of rate
// special handling of value 1 only used for voodoo chair
actor - > setTurnRate ( ( rate = = 1 ) ? 100 : rate ) ;
}
2012-09-16 23:18:27 +02:00
void Lua_V2 : : LockChoreSet ( ) {
lua_Object choreObj = lua_getparam ( 1 ) ;
const char * choreName = lua_getstring ( choreObj ) ;
warning ( " Lua_V2::LockChoreSet: chore: %s " , choreName ) ;
}
void Lua_V2 : : UnlockChoreSet ( ) {
lua_Object choreObj = lua_getparam ( 1 ) ;
const char * choreName = lua_getstring ( choreObj ) ;
warning ( " Lua_V2::UnlockChoreSet: chore: %s " , choreName ) ;
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : LockChore ( ) {
lua_Object nameObj = lua_getparam ( 1 ) ;
lua_Object filenameObj = lua_getparam ( 2 ) ;
if ( ! lua_isstring ( nameObj ) | | ! lua_isstring ( filenameObj ) ) {
lua_pushnil ( ) ;
return ;
}
const char * name = lua_getstring ( nameObj ) ;
const char * filename = lua_getstring ( filenameObj ) ;
warning ( " Lua_V2::LockChore, name: %s, filename: %s " , name , filename ) ;
// FIXME: implement missing rest part of code
}
2012-02-17 12:23:44 -08:00
void Lua_V2 : : UnlockChore ( ) {
lua_Object nameObj = lua_getparam ( 1 ) ;
lua_Object filenameObj = lua_getparam ( 2 ) ;
if ( ! lua_isstring ( nameObj ) | | ! lua_isstring ( filenameObj ) ) {
lua_pushnil ( ) ;
return ;
}
const char * name = lua_getstring ( nameObj ) ;
const char * filename = lua_getstring ( filenameObj ) ;
warning ( " Lua_V2::UnlockChore, name: %s, filename: %s " , name , filename ) ;
// FIXME: implement missing rest part of code
}
2013-11-29 22:16:59 +01:00
void Lua_V2 : : IsActorChoring ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
bool excludeLoop = getbool ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
2014-08-15 22:08:27 +03:00
const Common : : List < Costume * > & costumes = actor - > getCostumes ( ) ;
for ( Common : : List < Costume * > : : const_iterator it = costumes . begin ( ) ; it ! = costumes . end ( ) ; + + it ) {
Costume * costume = * it ;
for ( int i = 0 ; i < costume - > getNumChores ( ) ; i + + ) {
int chore = costume - > isChoring ( i , excludeLoop ) ;
if ( chore ! = - 1 ) {
// Ignore talk chores.
bool isTalk = false ;
for ( int j = 0 ; j < 10 ; j + + ) {
if ( costume = = actor - > getTalkCostume ( j ) & & actor - > getTalkChore ( j ) = = chore ) {
isTalk = true ;
break ;
}
}
if ( isTalk )
continue ;
2013-11-29 22:16:59 +01:00
2014-08-15 22:08:27 +03:00
lua_pushnumber ( chore ) ;
2013-11-29 22:16:59 +01:00
2014-08-15 22:08:27 +03:00
pushbool ( true ) ;
return ;
2013-11-29 22:16:59 +01:00
}
}
}
lua_pushnil ( ) ;
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : IsChoreValid ( ) {
2012-02-17 14:54:38 -08:00
lua_Object choreObj = lua_getparam ( 1 ) ;
2012-02-15 19:03:30 -08:00
2012-02-17 14:54:38 -08:00
if ( ! lua_isuserdata ( choreObj ) | | lua_tag ( choreObj ) ! = MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) )
2012-02-15 19:03:30 -08:00
return ;
2012-02-17 14:54:38 -08:00
int chore = lua_getuserdata ( choreObj ) ;
2013-12-07 13:06:39 +01:00
Chore * c = EMIChore : : getPool ( ) . getObject ( chore ) ;
2012-02-17 15:20:52 -08:00
if ( c ) {
2014-05-29 15:35:46 -07:00
pushbool ( c ! = nullptr ) ;
2012-02-17 15:20:52 -08:00
} else {
lua_pushnil ( ) ;
}
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : IsChorePlaying ( ) {
2012-02-17 14:54:38 -08:00
lua_Object choreObj = lua_getparam ( 1 ) ;
2012-02-15 19:03:30 -08:00
2012-02-17 14:54:38 -08:00
if ( ! lua_isuserdata ( choreObj ) | | lua_tag ( choreObj ) ! = MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) )
2012-02-15 19:03:30 -08:00
return ;
2012-02-17 14:54:38 -08:00
int chore = lua_getuserdata ( choreObj ) ;
2013-12-07 13:06:39 +01:00
Chore * c = EMIChore : : getPool ( ) . getObject ( chore ) ;
2012-02-17 15:20:52 -08:00
if ( c ) {
2014-08-02 21:59:55 +03:00
pushbool ( c - > isPlaying ( ) & & ! c - > isPaused ( ) ) ;
2012-02-17 15:20:52 -08:00
} else {
lua_pushnil ( ) ;
}
}
void Lua_V2 : : IsChoreLooping ( ) {
lua_Object choreObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( choreObj ) | | lua_tag ( choreObj ) ! = MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) )
return ;
2012-02-15 19:03:30 -08:00
2012-02-17 15:20:52 -08:00
int chore = lua_getuserdata ( choreObj ) ;
2013-12-07 13:06:39 +01:00
Chore * c = EMIChore : : getPool ( ) . getObject ( chore ) ;
2012-02-17 15:20:52 -08:00
if ( c ) {
pushbool ( c - > isLooping ( ) ) ;
} else {
lua_pushnil ( ) ;
}
2012-02-15 19:03:30 -08:00
}
2012-07-12 23:14:40 +02:00
void Lua_V2 : : SetChoreLooping ( ) {
lua_Object choreObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( choreObj ) | | lua_tag ( choreObj ) ! = MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) )
return ;
int chore = lua_getuserdata ( choreObj ) ;
2013-12-07 13:06:39 +01:00
Chore * c = EMIChore : : getPool ( ) . getObject ( chore ) ;
2012-07-12 23:14:40 +02:00
if ( c ) {
c - > setLooping ( false ) ;
}
lua_pushnil ( ) ;
}
2012-09-16 23:28:46 +02:00
void Lua_V2 : : PlayChore ( ) {
lua_Object choreObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( choreObj ) | | lua_tag ( choreObj ) ! = MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) )
return ;
int chore = lua_getuserdata ( choreObj ) ;
2014-05-28 18:10:53 +03:00
Chore * c = EMIChore : : getPool ( ) . getObject ( chore ) ;
if ( c ) {
c - > setPaused ( false ) ;
}
2012-09-16 23:28:46 +02:00
}
void Lua_V2 : : PauseChore ( ) {
lua_Object choreObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( choreObj ) | | lua_tag ( choreObj ) ! = MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) )
return ;
int chore = lua_getuserdata ( choreObj ) ;
2014-05-28 18:10:53 +03:00
Chore * c = EMIChore : : getPool ( ) . getObject ( chore ) ;
if ( c ) {
c - > setPaused ( true ) ;
}
2012-09-16 23:28:46 +02:00
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : StopChore ( ) {
lua_Object choreObj = lua_getparam ( 1 ) ;
2014-05-28 14:39:42 +03:00
lua_Object fadeTimeObj = lua_getparam ( 2 ) ;
2012-02-15 19:03:30 -08:00
2014-03-26 14:08:04 +02:00
if ( ! lua_isuserdata ( choreObj ) | | lua_tag ( choreObj ) ! = MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) )
2012-02-15 19:03:30 -08:00
return ;
2012-02-17 14:54:38 -08:00
int chore = lua_getuserdata ( choreObj ) ;
2014-05-28 14:39:42 +03:00
float fadeTime = 0.0f ;
2014-03-26 14:08:04 +02:00
2014-05-28 14:39:42 +03:00
if ( ! lua_isnil ( fadeTimeObj ) ) {
if ( lua_isnumber ( fadeTimeObj ) )
fadeTime = lua_getnumber ( fadeTimeObj ) ;
2014-03-26 14:08:04 +02:00
}
2014-08-03 16:45:36 +03:00
// There are a few cases in the scripts where StopChore is called with an excessively
// large fadeTime value. The original engine ignores fade times greater or equal
// to 0.6 seconds, so we replicate that behavior here.
if ( fadeTime > = 0.6f ) {
fadeTime = 0.0f ;
}
2013-12-07 13:06:39 +01:00
Chore * c = EMIChore : : getPool ( ) . getObject ( chore ) ;
2012-02-17 15:20:52 -08:00
if ( c ) {
2014-05-28 14:39:42 +03:00
c - > stop ( ( int ) ( fadeTime * 1000 ) ) ;
2012-02-17 15:20:52 -08:00
}
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : AdvanceChore ( ) {
lua_Object choreObj = lua_getparam ( 1 ) ;
lua_Object timeObj = lua_getparam ( 2 ) ;
2012-02-17 14:54:38 -08:00
if ( ! lua_isuserdata ( choreObj ) | | lua_tag ( choreObj ) ! = MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) | | ! lua_isnumber ( timeObj ) )
2012-02-15 19:03:30 -08:00
return ;
2012-02-17 14:54:38 -08:00
int chore = lua_getuserdata ( choreObj ) ;
2012-02-15 19:03:30 -08:00
float time = lua_getnumber ( timeObj ) ;
2013-12-07 13:06:39 +01:00
Chore * c = EMIChore : : getPool ( ) . getObject ( chore ) ;
2012-04-28 11:47:24 -07:00
if ( c ) {
2013-07-05 00:20:53 +02:00
if ( ! c - > isPlaying ( ) ) {
warning ( " AdvanceChore() called on stopped chore %s (%s) " ,
2013-07-09 21:12:55 +02:00
c - > getName ( ) , c - > getOwner ( ) - > getFilename ( ) . c_str ( ) ) ;
2013-07-05 00:20:53 +02:00
if ( c - > isLooping ( ) ) {
c - > getOwner ( ) - > playChoreLooping ( c - > getName ( ) ) ;
} else {
c - > getOwner ( ) - > playChore ( c - > getName ( ) ) ;
}
}
2014-05-26 14:42:53 +03:00
c - > advance ( time * 1000 ) ;
2012-04-28 11:47:24 -07:00
}
2012-02-15 19:03:30 -08:00
}
2013-07-12 17:06:50 +02:00
// TODO: Implement, verify, and rename parameters
void Lua_V2 : : CompleteChore ( ) {
lua_Object param1 = lua_getparam ( 1 ) ;
lua_Object param2 = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( param1 ) | | ! lua_isnumber ( param2 ) )
error ( " Lua_V2::CompleteChore - Unknown params " ) ;
// Guesswork based on StopChore:
int chore = lua_getuserdata ( param1 ) ;
float time = lua_getnumber ( param2 ) ;
error ( " Lua_V2::CompleteChore(%d, %f) - TODO: Implement opcode " , chore , time ) ;
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : SetActorSortOrder ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
2012-07-12 19:17:47 +02:00
lua_Object orderObj = lua_getparam ( 2 ) ;
2012-02-15 19:03:30 -08:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
2012-07-12 19:17:47 +02:00
if ( ! lua_isnumber ( orderObj ) )
2012-02-15 19:03:30 -08:00
return ;
Actor * actor = getactor ( actorObj ) ;
2012-07-12 19:17:47 +02:00
int order = ( int ) lua_getnumber ( orderObj ) ;
actor - > setSortOrder ( order ) ;
2013-07-14 10:16:27 -07:00
g_emi - > invalidateSortOrder ( ) ;
2012-02-15 19:03:30 -08:00
}
2012-02-18 14:13:28 -08:00
void Lua_V2 : : GetActorSortOrder ( ) {
2012-07-12 19:17:47 +02:00
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
2014-08-05 17:49:27 +03:00
lua_pushnumber ( actor - > getEffectiveSortOrder ( ) ) ;
2012-02-18 14:13:28 -08:00
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : ActorActivateShadow ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
2014-07-20 20:58:22 +03:00
lua_Object activeObj = lua_getparam ( 2 ) ;
2012-02-15 19:03:30 -08:00
lua_Object planeObj = lua_getparam ( 3 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2014-07-20 20:58:22 +03:00
bool active = ( int ) lua_getnumber ( activeObj ) = = 1 ;
const char * plane = nullptr ;
2012-02-15 19:03:30 -08:00
if ( lua_isstring ( planeObj ) )
plane = lua_getstring ( planeObj ) ;
2014-07-20 20:58:22 +03:00
actor - > activateShadow ( active , plane ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : ActorStopMoving ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
2014-05-25 20:59:19 -04:00
actor - > stopWalking ( ) ;
2014-08-18 07:56:54 -04:00
actor - > stopTurning ( ) ;
2014-05-25 20:59:19 -04:00
2012-02-15 19:03:30 -08:00
warning ( " Lua_V2::ActorStopMoving, actor: %s " , actor - > getName ( ) . c_str ( ) ) ;
2014-05-25 20:59:19 -04:00
// FIXME: Inspect the rest of the code to see if there's anything else missing
2012-02-15 19:03:30 -08:00
}
2014-06-30 19:39:09 +03:00
void Lua_V2 : : ActorLookAt ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object xObj = lua_getparam ( 2 ) ;
lua_Object yObj = lua_getparam ( 3 ) ;
lua_Object zObj = lua_getparam ( 4 ) ;
lua_Object rateObj = lua_getparam ( 5 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor - > getCurrentCostume ( ) )
return ;
if ( lua_isnumber ( rateObj ) )
actor - > setLookAtRate ( lua_getnumber ( rateObj ) ) ;
// Look at nothing
if ( lua_isnil ( xObj ) ) {
if ( actor - > isLookAtVectorZero ( ) )
return ;
actor - > setLookAtVectorZero ( ) ;
actor - > setLooking ( false ) ;
if ( lua_isnumber ( yObj ) & & lua_getnumber ( yObj ) > 0 )
actor - > setLookAtRate ( lua_getnumber ( yObj ) ) ;
return ;
} else if ( lua_isnumber ( xObj ) ) { // look at xyz
float fY ;
float fZ ;
float fX = lua_getnumber ( xObj ) ;
if ( lua_isnumber ( yObj ) )
fY = lua_getnumber ( yObj ) ;
else
fY = 0.0f ;
if ( lua_isnumber ( zObj ) )
fZ = lua_getnumber ( zObj ) ;
else
fZ = 0.0f ;
Math : : Vector3d vector ;
vector . set ( fX , fY , fZ ) ;
actor - > setLookAtVector ( vector ) ;
if ( lua_isnumber ( rateObj ) )
actor - > setLookAtRate ( lua_getnumber ( rateObj ) ) ;
} else if ( lua_isuserdata ( xObj ) & & lua_tag ( xObj ) = = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) ) { // look at another actor
Actor * lookedAct = getactor ( xObj ) ;
actor - > setLookAtActor ( lookedAct ) ;
if ( lua_isnumber ( yObj ) )
actor - > setLookAtRate ( lua_getnumber ( yObj ) ) ;
} else {
return ;
}
actor - > setLooking ( true ) ;
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : GetActorWorldPos ( ) {
2012-03-11 15:58:47 +01:00
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
Math : : Vector3d pos = actor - > getWorldPos ( ) ;
lua_pushnumber ( pos . x ( ) ) ;
lua_pushnumber ( pos . y ( ) ) ;
lua_pushnumber ( pos . z ( ) ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : PutActorInSet ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object setObj = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! lua_isstring ( setObj ) & & ! lua_isnil ( setObj ) ) {
lua_pushnil ( ) ;
return ;
}
const char * set = lua_getstring ( setObj ) ;
// FIXME verify adding actor to set
if ( ! set ) {
actor - > putInSet ( " " ) ;
lua_pushnil ( ) ;
} else {
if ( ! actor - > isInSet ( set ) ) {
actor - > putInSet ( set ) ;
}
lua_pushnumber ( 1.0 ) ;
}
}
2012-02-28 00:18:36 +01:00
void Lua_V2 : : SetActorRestChore ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object choreObj = lua_getparam ( 2 ) ;
lua_Object costumeObj = lua_getparam ( 3 ) ;
2014-05-29 15:35:46 -07:00
Costume * costume = nullptr ;
2014-08-04 22:25:55 -07:00
int chore = - 1 ;
2012-02-28 00:18:36 +01:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) | |
( ! lua_isstring ( choreObj ) & & ! lua_isnil ( choreObj ) ) ) {
return ;
}
Actor * actor = getactor ( actorObj ) ;
2014-01-04 20:19:06 +01:00
setChoreAndCostume ( choreObj , costumeObj , actor , costume , chore ) ;
2012-02-28 00:18:36 +01:00
actor - > setRestChore ( chore , costume ) ;
}
void Lua_V2 : : SetActorWalkChore ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object choreObj = lua_getparam ( 2 ) ;
lua_Object costumeObj = lua_getparam ( 3 ) ;
2014-05-29 15:35:46 -07:00
Costume * costume = nullptr ;
2014-08-04 22:25:55 -07:00
int chore = - 1 ;
2012-02-28 00:18:36 +01:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) | |
( ! lua_isstring ( choreObj ) & & ! lua_isnil ( choreObj ) ) ) {
return ;
}
Actor * actor = getactor ( actorObj ) ;
2014-01-04 20:19:06 +01:00
setChoreAndCostume ( choreObj , costumeObj , actor , costume , chore ) ;
2012-02-28 00:18:36 +01:00
actor - > setWalkChore ( chore , costume ) ;
}
void Lua_V2 : : SetActorTurnChores ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object leftChoreObj = lua_getparam ( 2 ) ;
lua_Object rightChoreObj = lua_getparam ( 3 ) ;
lua_Object costumeObj = lua_getparam ( 4 ) ;
Costume * costume ;
2013-11-30 09:23:19 +01:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) ) {
return ;
} else if ( ! lua_isnil ( leftChoreObj ) & & ! lua_isstring ( leftChoreObj ) ) {
return ;
} else if ( ! lua_isnil ( rightChoreObj ) & & ! lua_isstring ( rightChoreObj ) ) {
2012-02-28 00:18:36 +01:00
return ;
}
Actor * actor = getactor ( actorObj ) ;
if ( ! findCostume ( costumeObj , actor , & costume ) )
return ;
int leftChore = costume - > getChoreId ( lua_getstring ( leftChoreObj ) ) ;
int rightChore = costume - > getChoreId ( lua_getstring ( rightChoreObj ) ) ;
actor - > setTurnChores ( leftChore , rightChore , costume ) ;
}
void Lua_V2 : : SetActorTalkChore ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object indexObj = lua_getparam ( 2 ) ;
lua_Object choreObj = lua_getparam ( 3 ) ;
lua_Object costumeObj = lua_getparam ( 4 ) ;
2014-05-29 15:35:46 -07:00
Costume * costume = nullptr ;
2014-08-04 22:25:55 -07:00
int chore = - 1 ;
2012-02-28 00:18:36 +01:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) | |
! lua_isnumber ( indexObj ) | |
( ! lua_isstring ( choreObj ) & & ! lua_isnil ( choreObj ) ) ) {
return ;
}
int index = ( int ) lua_getnumber ( indexObj ) ;
2014-05-24 00:42:36 +03:00
if ( index < 0 | | index > = 16 )
2012-02-28 00:18:36 +01:00
return ;
Actor * actor = getactor ( actorObj ) ;
2014-01-04 20:19:06 +01:00
setChoreAndCostume ( choreObj , costumeObj , actor , costume , chore ) ;
2012-02-28 00:18:36 +01:00
2014-05-24 00:42:36 +03:00
actor - > setTalkChore ( index + 1 , chore , costume ) ;
2012-02-28 00:18:36 +01:00
}
void Lua_V2 : : SetActorMumblechore ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object choreObj = lua_getparam ( 2 ) ;
lua_Object costumeObj = lua_getparam ( 3 ) ;
2014-05-29 15:35:46 -07:00
Costume * costume = nullptr ;
2014-08-04 22:25:55 -07:00
int chore = - 1 ;
2012-02-28 00:18:36 +01:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) | |
( ! lua_isstring ( choreObj ) & & ! lua_isnil ( choreObj ) ) ) {
return ;
}
Actor * actor = getactor ( actorObj ) ;
2014-01-04 20:19:06 +01:00
setChoreAndCostume ( choreObj , costumeObj , actor , costume , chore ) ;
2012-02-28 00:18:36 +01:00
actor - > setMumbleChore ( chore , costume ) ;
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : GetActorChores ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
2012-02-17 15:20:52 -08:00
Actor * actor = getactor ( actorObj ) ;
2014-08-15 22:01:57 +03:00
const Common : : List < Costume * > & costumes = actor - > getCostumes ( ) ;
2012-02-15 19:03:30 -08:00
lua_Object result = lua_createtable ( ) ;
2014-08-15 22:01:57 +03:00
int count = 0 ;
for ( Common : : List < Costume * > : : const_iterator it = costumes . begin ( ) ; it ! = costumes . end ( ) ; + + it ) {
const Common : : List < Chore * > & playingChores = ( * it ) - > getPlayingChores ( ) ;
for ( Common : : List < Chore * > : : const_iterator cit = playingChores . begin ( ) ; cit ! = playingChores . end ( ) ; + + cit ) {
lua_pushobject ( result ) ;
lua_pushnumber ( count + + ) ;
lua_pushusertag ( ( ( EMIChore * ) * cit ) - > getId ( ) , MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) ) ;
lua_settable ( ) ;
}
2012-02-18 14:13:28 -08:00
}
2014-08-15 22:01:57 +03:00
lua_pushobject ( result ) ;
2012-02-15 19:03:30 -08:00
lua_pushstring ( " count " ) ;
2014-08-15 22:01:57 +03:00
lua_pushnumber ( count ) ;
2012-02-15 19:03:30 -08:00
lua_settable ( ) ;
lua_pushobject ( result ) ;
}
2014-09-24 22:36:50 +02:00
// Helper function, not called from LUA directly
2013-12-11 23:19:23 +01:00
bool Lua_V2 : : findCostume ( lua_Object costumeObj , Actor * actor , Costume * * costume ) {
2014-05-29 15:35:46 -07:00
* costume = nullptr ;
2014-08-15 21:08:20 +03:00
if ( lua_isnil ( costumeObj ) ) {
* costume = actor - > getCurrentCostume ( ) ;
} else {
if ( lua_isstring ( costumeObj ) ) {
const char * costumeName = lua_getstring ( costumeObj ) ;
2013-12-11 23:19:23 +01:00
* costume = actor - > findCostume ( costumeName ) ;
2014-08-15 21:08:20 +03:00
if ( * costume = = nullptr ) {
actor - > pushCostume ( costumeName ) ;
* costume = actor - > findCostume ( costumeName ) ;
}
2013-12-11 23:19:23 +01:00
}
}
2014-05-29 15:35:46 -07:00
return ( * costume ! = nullptr ) ;
2013-12-11 23:19:23 +01:00
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : PlayActorChore ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object choreObj = lua_getparam ( 2 ) ;
lua_Object costumeObj = lua_getparam ( 3 ) ;
2012-07-07 19:07:33 +02:00
lua_Object modeObj = lua_getparam ( 4 ) ;
2014-05-22 19:56:27 +03:00
lua_Object fadeTimeObj = lua_getparam ( 5 ) ;
2012-02-15 19:03:30 -08:00
2014-05-28 14:39:42 +03:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
2012-02-15 19:03:30 -08:00
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! lua_isstring ( choreObj ) | | ! lua_isstring ( costumeObj ) )
lua_pushnil ( ) ;
2012-07-07 19:07:33 +02:00
bool mode = false ;
2014-05-22 19:56:27 +03:00
float fadeTime = 0.0f ;
2012-02-15 19:03:30 -08:00
if ( ! lua_isnil ( modeObj ) ) {
if ( lua_getnumber ( modeObj ) ! = 0.0 )
mode = true ;
2014-05-22 19:56:27 +03:00
}
if ( ! lua_isnil ( fadeTimeObj ) ) {
if ( lua_isnumber ( fadeTimeObj ) )
fadeTime = lua_getnumber ( fadeTimeObj ) ;
2012-07-07 19:07:33 +02:00
}
2012-02-15 19:03:30 -08:00
const char * choreName = lua_getstring ( choreObj ) ;
2012-04-24 17:07:46 -07:00
2013-12-11 23:19:23 +01:00
Costume * costume ;
if ( ! findCostume ( costumeObj , actor , & costume ) )
return ;
2012-02-25 15:15:08 -08:00
2013-12-07 13:06:39 +01:00
EMIChore * chore = ( EMIChore * ) costume - > getChore ( choreName ) ;
2012-07-07 19:07:33 +02:00
if ( mode ) {
2014-05-28 14:39:42 +03:00
costume - > playChoreLooping ( choreName , ( int ) ( fadeTime * 1000 ) ) ;
2012-07-07 19:07:33 +02:00
} else {
2014-05-28 14:39:42 +03:00
costume - > playChore ( choreName , ( int ) ( fadeTime * 1000 ) ) ;
2014-05-22 19:56:27 +03:00
}
2012-02-15 19:03:30 -08:00
if ( chore ) {
2012-02-17 14:54:38 -08:00
lua_pushusertag ( chore - > getId ( ) , MKTAG ( ' C ' , ' H ' , ' O ' , ' R ' ) ) ;
2012-02-15 19:03:30 -08:00
} else {
lua_pushnil ( ) ;
}
}
void Lua_V2 : : StopActorChores ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
2014-01-24 22:39:14 +01:00
// Guesswork for boolean parameter
bool ignoreLoopingChores = getbool ( 2 ) ;
2012-02-15 19:03:30 -08:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2014-01-24 22:39:14 +01:00
actor - > stopAllChores ( ignoreLoopingChores ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : SetActorLighting ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object lightModeObj = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
if ( lua_isnil ( lightModeObj ) | | ! lua_isnumber ( lightModeObj ) )
return ;
int lightMode = ( int ) lua_getnumber ( lightModeObj ) ;
2014-06-09 18:42:57 +03:00
actor - > setLightMode ( ( Actor : : LightMode ) lightMode ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : SetActorCollisionMode ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object modeObj = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
assert ( actor ) ;
int mode = ( int ) lua_getnumber ( modeObj ) ;
2013-12-22 03:22:09 +01:00
Actor : : CollisionMode m ;
switch ( mode ) {
case Actor : : CollisionOff :
m = Actor : : CollisionOff ;
break ;
case Actor : : CollisionBox :
m = Actor : : CollisionBox ;
break ;
case Actor : : CollisionSphere :
m = Actor : : CollisionSphere ;
break ;
default :
warning ( " Lua_V2::SetActorCollisionMode(): wrong collisionmode: %d, using default 0 " , mode ) ;
m = Actor : : CollisionOff ;
}
actor - > setCollisionMode ( m ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : SetActorCollisionScale ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object scaleObj = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
assert ( actor ) ;
float scale = lua_getnumber ( scaleObj ) ;
2013-12-22 03:22:09 +01:00
actor - > setCollisionScale ( scale ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : GetActorPuckVector ( ) {
2012-02-07 00:04:09 +01:00
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object addObj = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) ) {
lua_pushnil ( ) ;
return ;
}
Actor * actor = getactor ( actorObj ) ;
2014-06-16 21:36:55 +03:00
// Note: The wear chore of dumbshadow.cos is only started from Lua if
// GetActorPuckVector returns a non-nil value. The original engine seems
// to return nil for all actors that have never followed walkboxes.
2022-01-06 16:23:13 +01:00
if ( ! actor | | ( ! actor - > hasFollowedBoxes ( ) & & ! actor - > hasFollowBoxes ( ) ) ) {
2012-02-07 00:04:09 +01:00
lua_pushnil ( ) ;
return ;
}
Math : : Vector3d result = actor - > getPuckVector ( ) ;
if ( ! lua_isnil ( addObj ) )
result + = actor - > getPos ( ) ;
lua_pushnumber ( result . x ( ) ) ;
lua_pushnumber ( result . y ( ) ) ;
lua_pushnumber ( result . z ( ) ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : SetActorHeadLimits ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
2014-06-26 16:34:05 +03:00
lua_Object yawObj = lua_getparam ( 2 ) ;
lua_Object maxPitchObj = lua_getparam ( 3 ) ;
lua_Object minPitchObj = lua_getparam ( 4 ) ;
2012-02-15 19:03:30 -08:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2014-06-26 16:34:05 +03:00
if ( lua_isnumber ( yawObj ) & & lua_isnumber ( minPitchObj ) & & lua_isnumber ( maxPitchObj ) ) {
float yaw = lua_getnumber ( yawObj ) ;
float maxPitch = lua_getnumber ( maxPitchObj ) ;
float minPitch = lua_getnumber ( minPitchObj ) ;
actor - > setHeadLimits ( yaw / 2 , maxPitch , - minPitch ) ;
2012-02-15 19:03:30 -08:00
}
}
2014-07-01 16:08:42 +03:00
void Lua_V2 : : SetActorHead ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object jointObj = lua_getparam ( 2 ) ;
lua_Object xObj = lua_getparam ( 3 ) ;
lua_Object yObj = lua_getparam ( 4 ) ;
lua_Object zObj = lua_getparam ( 5 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2014-07-15 18:13:30 +03:00
if ( lua_isstring ( jointObj ) ) {
2014-07-01 16:08:42 +03:00
const char * joint = lua_getstring ( jointObj ) ;
Math : : Vector3d offset ;
offset . x ( ) = lua_getnumber ( xObj ) ;
offset . y ( ) = lua_getnumber ( yObj ) ;
offset . z ( ) = lua_getnumber ( zObj ) ;
actor - > setHead ( joint , offset ) ;
}
}
2012-02-15 19:03:30 -08:00
void Lua_V2 : : SetActorFOV ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object fovObj = lua_getparam ( 2 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
if ( lua_isnumber ( fovObj ) ) {
float fov = lua_getnumber ( fovObj ) ;
// FIXME: implement missing code
//actor->func(fov); // cos(fov * some tuntime val * 0.5)
warning ( " Lua_V2::SetActorFOV: implement opcode. actor: %s, param: %f " , actor - > getName ( ) . c_str ( ) , fov ) ;
}
}
void Lua_V2 : : AttachActor ( ) {
// Missing lua parts
2012-03-11 14:36:14 +01:00
lua_Object attachedObj = lua_getparam ( 1 ) ;
lua_Object actorObj = lua_getparam ( 2 ) ;
2012-03-11 15:24:52 +01:00
lua_Object jointObj = lua_getparam ( 3 ) ;
2012-03-11 14:36:14 +01:00
2013-07-09 21:12:55 +02:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
2012-03-11 14:36:14 +01:00
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
2013-07-09 21:12:55 +02:00
if ( ! lua_isuserdata ( attachedObj ) | | lua_tag ( attachedObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
2012-03-11 14:36:14 +01:00
return ;
Actor * attached = getactor ( attachedObj ) ;
if ( ! attached )
return ;
2014-05-29 15:35:46 -07:00
const char * joint = nullptr ;
2012-03-11 15:24:52 +01:00
if ( ! lua_isnil ( jointObj ) ) {
joint = lua_getstring ( jointObj ) ;
2012-03-11 14:36:14 +01:00
}
2012-03-11 15:24:52 +01:00
attached - > attachToActor ( actor , joint ) ;
2014-10-11 12:36:42 +02:00
Debug : : debug ( Debug : : Actors | Debug : : Scripts , " Lua_V2::AttachActor: attaching %s to %s (on %s) " , attached - > getName ( ) . c_str ( ) , actor - > getName ( ) . c_str ( ) , joint ? joint : " (none) " ) ;
2013-11-29 08:39:42 -08:00
g_emi - > invalidateSortOrder ( ) ;
2012-02-15 19:03:30 -08:00
}
void Lua_V2 : : DetachActor ( ) {
// Missing lua parts
2012-03-11 14:36:14 +01:00
lua_Object attachedObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( attachedObj ) | | lua_tag ( attachedObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * attached = getactor ( attachedObj ) ;
if ( ! attached )
return ;
2014-10-11 12:36:42 +02:00
Debug : : debug ( Debug : : Actors | Debug : : Scripts , " Lua_V2::DetachActor: detaching %s from parent actor " , attached - > getName ( ) . c_str ( ) ) ;
2012-03-11 15:24:52 +01:00
attached - > detach ( ) ;
2013-12-29 13:29:34 +01:00
g_emi - > invalidateSortOrder ( ) ;
2012-02-15 19:03:30 -08:00
}
2012-08-19 12:16:28 -07:00
void Lua_V2 : : WalkActorToAvoiding ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
lua_Object actor2Obj = lua_getparam ( 2 ) ;
lua_Object xObj = lua_getparam ( 3 ) ;
lua_Object yObj = lua_getparam ( 4 ) ;
lua_Object zObj = lua_getparam ( 5 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
if ( ! lua_isuserdata ( actor2Obj ) | | lua_tag ( actor2Obj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Math : : Vector3d destVec ;
Actor * actor = getactor ( actorObj ) ;
if ( ! lua_isnumber ( xObj ) ) {
if ( ! lua_isuserdata ( xObj ) | | lua_tag ( xObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * destActor = getactor ( xObj ) ;
destVec = destActor - > getPos ( ) ;
} else {
float x = lua_getnumber ( xObj ) ;
float y = lua_getnumber ( yObj ) ;
float z = lua_getnumber ( zObj ) ;
destVec . set ( x , y , z ) ;
}
// TODO: Make this actually avoid the second actor
actor - > walkTo ( destVec ) ;
}
2014-07-27 21:24:10 +03:00
void Lua_V2 : : WalkActorVector ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
2022-06-08 01:12:00 +02:00
//lua_Object xObj = lua_getparam(3);
//lua_Object yObj = lua_getparam(4);
//lua_Object zObj = lua_getparam(5);
//lua_Object param6Obj = lua_getparam(6);
2014-07-27 21:24:10 +03:00
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
2022-06-08 01:12:00 +02:00
//Actor *actor = static_cast<Actor *>(lua_getuserdata(actorObj));
2014-07-27 21:24:10 +03:00
Actor * actor2 = getactor ( actorObj ) ;
// TODO whole below part need rewrote to much original
float moveHoriz , moveVert ;
// Third option is the "left/right" movement
moveHoriz = luaL_check_number ( 2 ) ;
// Fourth Option is the "up/down" movement
moveVert = luaL_check_number ( 4 ) ;
// Get the direction the camera is pointing
Set : : Setup * setup = g_grim - > getCurrSet ( ) - > getCurrSetup ( ) ;
Math : : Vector3d cameraVector ( 0 , 0 , 1 ) ;
2014-08-19 21:15:18 -04:00
setup - > _rot . transform ( & cameraVector , false ) ;
2014-07-27 21:24:10 +03:00
// find the angle the camera direction is around the unit circle
Math : : Angle cameraYaw = Math : : Angle : : arcTangent2 ( cameraVector . x ( ) , cameraVector . z ( ) ) ;
// Handle the turning
Math : : Vector3d adjustVector ( moveHoriz , 0 , moveVert ) ;
// find the angle the adjust vector is around the unit circle
Math : : Angle adjustYaw = Math : : Angle : : arcTangent2 ( adjustVector . x ( ) , adjustVector . z ( ) ) ;
Math : : Angle yaw = cameraYaw + adjustYaw ;
// set the new direction or walk forward
if ( actor2 - > getYaw ( ) ! = yaw )
actor2 - > turnTo ( 0 , yaw , 0 , true ) ;
actor2 - > walkForward ( ) ;
}
2013-05-22 01:35:49 +02:00
void Lua_V2 : : EnableActorPuck ( ) {
lua_Object actorObj = lua_getparam ( 1 ) ;
if ( ! lua_isuserdata ( actorObj ) | | lua_tag ( actorObj ) ! = MKTAG ( ' A ' , ' C ' , ' T ' , ' R ' ) )
return ;
Actor * actor = getactor ( actorObj ) ;
if ( ! actor )
return ;
bool enable = getbool ( 2 ) ;
// FIXME: Implement.
warning ( " Lua_V2::EnableActorPuck: stub, actor: %s enable: %s " , actor - > getName ( ) . c_str ( ) , enable ? " TRUE " : " FALSE " ) ;
}
2014-09-24 22:36:50 +02:00
// Helper function, not called from LUA directly
2014-01-04 20:19:06 +01:00
void Lua_V2 : : setChoreAndCostume ( lua_Object choreObj , lua_Object costumeObj , Actor * actor , Costume * & costume , int & chore ) {
if ( lua_isnil ( choreObj ) ) {
2014-08-04 22:25:55 -07:00
return ;
}
if ( ! findCostume ( costumeObj , actor , & costume ) )
return ;
2014-01-04 20:19:06 +01:00
2014-08-04 22:25:55 -07:00
const char * choreStr = lua_getstring ( choreObj ) ;
chore = costume - > getChoreId ( choreStr ) ;
2014-01-04 20:19:06 +01:00
}
2012-02-15 19:03:30 -08:00
} // end of namespace Grim