Simba Code:
Type TModel = Record
xVertices, yVertices, zVertices : TIntegerArray;
xIndices, yIndices, zIndices : TIntegerArray;
tile: TPoint;
verticesLength, indicesLength: Integer;
end;
TModelArray = Array of TModel;
function NULL_MODEL: TModel;
begin
with Result do
begin
Tile := Point(0, 0);
end;
end;
(*
R_NewModel
~~~~~~~~~~~
.. code-block:: pascal
function R_NewModel(obj : Integer): TModel;
Generates a TModel from a Java model
.. note::
by Cheddy
*)
function R_NewModel(obj : Integer): TModel;
var
i : Integer;
begin
with Result do
begin
verticesLength := SmartGetFieldInt(SmartCurrentTarget, obj, Model_VerticesLength);
indicesLength := SmartGetFieldInt(SmartCurrentTarget, obj, Model_IndicesLength);
for i := 0 to verticesLength do
begin
xVertices[i] := SmartGetFieldArrayInt(SmartCurrentTarget, obj, Model_VerticesX, i);
yVertices[i] := SmartGetFieldArrayInt(SmartCurrentTarget, obj, Model_VerticesY, i);
zVertices[i] := SmartGetFieldArrayInt(SmartCurrentTarget, obj, Model_VerticesZ, i);
end;
for i := 0 to indicesLength do
begin
xIndices[i] := SmartGetFieldArrayInt(SmartCurrentTarget, obj, Model_IndicesX, i);
yIndices[i] := SmartGetFieldArrayInt(SmartCurrentTarget, obj, Model_IndicesY, i);
zIndices[i] := SmartGetFieldArrayInt(SmartCurrentTarget, obj, Model_IndicesZ, i);
end;
end;
end;
(*
R_GetWorldObjectModel
~~~~~~~~~~~
.. code-block:: pascal
function R_GetWorldObjectModel(ob : Integer): TModel;
Gets the model associated with a world object
.. note::
by Cheddy
*)
function R_GetWorldObjectModel(ob : Integer): TModel;
var
obj : Integer;
begin
obj := SmartGetFieldObject(SmartCurrentTarget, ob, WorldObject_Renderable);
Result := R_NewModel(obj);
Result.tile := Point(SmartGetFieldInt(SmartCurrentTarget, ob, WorldObject_Get_X) * WorldObject_Get_X_Multiplier, SmartGetFieldInt(SmartCurrentTarget, ob, WorldObject_Get_Y) * WorldObject_Get_Y_Multiplier);
SmartFreeObject(SmartCurrentTarget, obj);
end;
(*
R_GetBoundaryObjectModel
~~~~~~~~~~~
.. code-block:: pascal
function R_GetBoundaryObjectModel(ob : Integer): TModel;
Gets the model associated with a boundary object
.. note::
by Cheddy
*)
function R_GetBoundaryObjectModel(ob : Integer): TModel;
var
obj : Integer;
begin
obj := SmartGetFieldObject(SmartCurrentTarget, ob, BoundaryObject_Renderable);
Result := R_NewModel(obj);
Result.tile := Point(SmartGetFieldInt(SmartCurrentTarget, ob, BoundaryObject_Get_X) * BoundaryObject_Get_X_Multiplier, SmartGetFieldInt(SmartCurrentTarget, ob, BoundaryObject_Get_Y) * BoundaryObject_Get_Y_Multiplier);
SmartFreeObject(SmartCurrentTarget, obj);
end;
(*
R_GetFloorDecorationObjectModel
~~~~~~~~~~~
.. code-block:: pascal
function R_GetFloorDecorationObjectModel(ob : Integer): TModel;
Gets the model associated with a floor decoration object
.. note::
by Cheddy
*)
function R_GetFloorDecorationObjectModel(ob : Integer): TModel;
var
obj : Integer;
begin
obj := SmartGetFieldObject(SmartCurrentTarget, ob, FloorDecorationObject_Renderable);
Result := R_NewModel(obj);
Result.tile := Point(SmartGetFieldInt(SmartCurrentTarget, ob, FloorDecorationObject_Get_X) * FloorDecorationObject_Get_X_Multiplier, SmartGetFieldInt(SmartCurrentTarget, ob, FloorDecorationObject_Get_Y) * FloorDecorationObject_Get_Y_Multiplier);
SmartFreeObject(SmartCurrentTarget, obj);
end;
(*
R_GetWallObjectModel
~~~~~~~~~~~
.. code-block:: pascal
function R_GetWallObjectModel(ob : Integer): TModel;
Gets the model associated with a wall object
.. note::
by Cheddy
*)
function R_GetWallObjectModel(ob : Integer): TModel;
var
obj : Integer;
begin
obj := SmartGetFieldObject(SmartCurrentTarget, ob, WallObject_Renderable);
Result := R_NewModel(obj);
Result.tile := Point(SmartGetFieldInt(SmartCurrentTarget, ob, WallObject_X) * WallObject_X_Multiplier, SmartGetFieldInt(SmartCurrentTarget, ob, WallObject_Y) * WallObject_Y_Multiplier);
SmartFreeObject(SmartCurrentTarget, obj);
end;
(*
R_GetPolygons
~~~~~~~~~~~
.. code-block:: pascal
function function R_GetPolygons(model : TModel): T2DPointArray;
Gets the clickable polygons for a model.
.. note::
by Cheddy
*)
function R_GetPolygons(model : TModel): T2DPointArray;
var
p1,p2,p3 : TPoint;
polys : T2DPointArray;
i : Integer;
begin
for i := 0 to High(model.xVertices) do
begin
p1 := R_TileToMSEx(model.tile.x + model.xVertices[model.xIndices[i]],model.tile.y + model.zVertices[model.xIndices[i]], 0 - model.yVertices[model.xIndices[i]]);
p2 := R_TileToMSEx(model.tile.x + model.xVertices[model.yIndices[i]],model.tile.y + model.zVertices[model.yIndices[i]], 0 - model.yVertices[model.yIndices[i]]);
p3 := R_TileToMSEx(model.tile.x + model.xVertices[model.zIndices[i]],model.tile.y + model.zVertices[model.zIndices[i]], 0 - model.yVertices[model.zIndices[i]]);
if((p1.x >= 0) and (p2.x >= 0) and (p3.x >= 0)) then
begin
polys[High(polys)] := [p1, p2, p3];
end;
end;
result := polys;
end;
(*
R_RandomModelPoint
~~~~~~~~~~~
.. code-block:: pascal
function R_RandomModelPoint(model : TModel): TPoint;
Gets a random clickable point within a TModel
.. note::
by Cheddy
*)
function R_RandomModelPoint(model : TModel): TPoint;
var
atpa : T2DPointArray;
tpa : TPointArray;
tempPoint : TPoint;
i : Integer;
begin
atpa := R_GetPolygons(model);
for i := 0 to 100 do
begin
tpa := atpa[RandomRange(0, High(atpa))];
tempPoint := Point(tpa[RandomRange(Low(tpa), High(tpa))].x,tpa[RandomRange(Low(tpa), High(tpa))].y);
if(PointInBox(tempPoint, MSBox)) then
begin
result := tempPoint;
exit;
end;
end;
if(not PointInBox(tempPoint, MSBox)) then
begin
result := Point(-1, -1);
exit;
end;
end;
(*
R_ClickModel
~~~~~~~~~~~
.. code-block:: pascal
function R_ClickModel(model : TModel, left : Boolean): Boolean;
Returns whether the NPC is moving or not.
.. note::
by Cheddy
*)
function R_ClickModel(model : TModel; button : Variant): Boolean;
var
p : TPoint;
begin
p := R_RandomModelPoint(model);
if(not PointInBox(p, MSBox)) then
begin
result := false;
exit;
end;
Mouse(p.x,p.y,0,0, button);
result := true;
end;