File: LuaEntity.h

package info (click to toggle)
arkrpg 0.1.4b-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,104 kB
  • ctags: 5,445
  • sloc: cpp: 28,145; sh: 9,006; ansic: 3,259; makefile: 344
file content (152 lines) | stat: -rwxr-xr-x 4,481 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* $Id: LuaEntity.h,v 1.5 2003/02/14 13:40:28 mat Exp $
**
** Ark - Libraries, Tools & Programs for MMORPG developpements.
** Copyright (C) 1999-2000 The Contributors of the Ark Project
** Please see the file "AUTHORS" for a list of contributors
**
** 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef ARK_LUAENTITY_H
#define ARK_LUAENTITY_H

#include <Modules/Lua/ArkLua.h>

#include <Engine/Entity.h>
#include <Modules/Lua/luna.h>
#include <Modules/Lua/LuaListTable.h>

namespace Ark
{
   EngineEntity *CreateLuaEntity();

   class ARKLUA_DLL_API LuaEntity : public EngineEntity, public LunaObject
   {
      public:
	 static const char className[];
	 static const Luna<LuaEntity>::RegType Register[];

      private:
	 String m_Callback;
	 bool push_check_objfunction (const String &fname);

      public:
	 LuaEntity(lua_State *L);
	 ~LuaEntity();

	 /// Name, short name, identifier
	 int get_name (lua_State *L);
	 int set_name (lua_State *L);
	 int get_shortname (lua_State *L);
	 int set_shortname (lua_State *L);
	 int get_id (lua_State *L);

	 /// Callbacks
	 int add_timer (lua_State *L);
	 int add_message (lua_State *L);

	 /// Visual
	 int psys_set (lua_State *L);
	 int psys_stop (lua_State *L);
	 int psys_exists (lua_State *L);
	 int set_model (lua_State *L);
	 int get_model (lua_State *L);
	 int play_anim (lua_State *L);
	 int play_sound (lua_State *L);
	 int play_music (lua_State *L);

	 /// Position
	 int set_position (lua_State *L);
	 int set_entity_goal (lua_State *L);
	 int set_position_goal (lua_State *L);
	 int set_no_goal (lua_State *L);
	 int get_position (lua_State *L);
      
	 /// Flags
#define FLAGACCESSOR(func, flagvalue)                               \
      int is_ ## func (lua_State *L);                               \
      int set_ ## func (lua_State *L);

	 FLAGACCESSOR (aidriven, AIDRIVEN);
	 FLAGACCESSOR (dead, DEAD);
	 FLAGACCESSOR (visible, VISIBLE);
	 FLAGACCESSOR (collider, COLLISION);
	 FLAGACCESSOR (staticp, STATIC);
#undef FLAGACCESSOR
	 
	 /// Clear changed flag
	 int clear_changed (lua_State *L);
      
	 /// Entity binding.
	 int attach_to_entity (lua_State *L);
	 int is_attached (lua_State *L);

	 /// Entity management
	 int set_entries (lua_State *L);
	 int set_callback_entries (lua_State *L);
	 int set_callback (lua_State *L);
	 int get_callback (lua_State *L);

	 //////////////////////////////////////////////////////////////////////
	 //////////////////////////////////////////////////////////////////////
	 //////////////////////////////////////////////////////////////////////

	 // === Functions to be implemented by script entities ===

	 //////////////////////////////////////////////////////////////////////
	 //////////////////////////////////////////////////////////////////////
	 //////////////////////////////////////////////////////////////////////

	 bool SetEntries (Engine *engine, const Ark::EntryList &entries);
	 bool SetCallback (Engine *engine, const Ark::EntryList &entries);

	 virtual void Create ();
	 virtual bool EvGoalReached ();
	 virtual bool EvTimer (int n);
	 virtual bool EvTell ();
	 void EvHit (const EntityCollision &col);
   };

   extern ARKLUA_DLL_API lua_State *g_LuaState;

  /**
  * Allow to manage list of entities.
  */
  class ARKLUA_DLL_API LuaEntityList : public LuaListTable
  {
    public:
    /**
     * Constructor
     */
    LuaEntityList(lua_State* L, int index = -1) : LuaListTable(L, index) {}
    
    /**
     * Add an element to the list
     *
     * \param element The element to add.
     */
    void addElement(LuaEntity& element);

    /**
     * Constructs a LuaEntityList from scratch. This creates a new table on
     * the stack.
     *
     * \param L The lua state where we are going to create the table.
     */
    static LuaEntityList* createTable(lua_State* L);
  };
}

#endif