Skip to content

Commit

Permalink
Stunts working!
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Feb 27, 2023
1 parent 62d3756 commit 97e94bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
7 changes: 5 additions & 2 deletions resources/scripts/missions.as
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ class MissionManager
sobj.type = reader.GetTokString(7);
if ((reader.GetTokType(8) == TOKEN_TYPE_STRING))
{
sobj.instanceName = reader.GetTokString(7);
sobj.instanceName = reader.GetTokString(8);
}
}
// An unique instance name is needed for proper unloading later.
// If none or empty specified in .mission file, generate one.
if (sobj.instanceName == "")
{
sobj.instanceName = filename + ":" + this.uniqueIdCounter++;
sobj.instanceName = filename + "/" + this.uniqueIdCounter++;
}
mission.terrainObjects.insertLast(sobj);
}
Expand Down Expand Up @@ -322,6 +322,8 @@ class MissionBuilder

bool buildStunt()
{
game.log("DEBUG >> MissionBuilder.buildStunt()");

// make sure stuntmanager exits
if (@stunts == null)
@stunts = StuntsManager();
Expand All @@ -336,6 +338,7 @@ class MissionBuilder
this.stuntStartObjInstance, this.stuntStartBoxName,
this.stuntEndObjInstance, this.stuntEndBoxName);

game.log("DEBUG << MissionBuilder.buildStunt()");
return true;
}

Expand Down
47 changes: 28 additions & 19 deletions resources/scripts/stunts.as
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ class StuntsManager

// add the eventcallback method if it doesn't exist
if(game.scriptFunctionExists("void eventCallbackEx(scriptEvents, int, int, int, int, string, string, string, string)")<0)
{
game.log("DEBUG StuntsManager.StuntManager(): binding `eventCallbackEx()`");
game.addScriptFunction("void eventCallbackEx(scriptEvents event, int arg1, int arg2ex, int arg3ex, int arg4ex, string arg5ex, string arg6ex, string arg7ex, string arg8ex){ stunts.eventCallbackEx(event, arg1, arg2ex, arg3ex, arg4ex, arg5ex, arg6ex, arg7ex, arg8ex); }");
}

// add the framestep function if it doesn't exist yet
if (game.scriptFunctionExists("void frameStep(float)")<0)
{
game.log("DEBUG StuntsManager.StuntManager(): binding `frameStep()`");
game.addScriptFunction("void frameStep(float dt) { stunts.frameStep(dt); }");
}

}

Expand All @@ -45,8 +51,8 @@ class StuntsManager

void onEventboxExitCallback(int truckNum, string objInstance, string boxName)
{
const int stuntCount = this.getStuntCount();
for (int i = 0; i < stuntCount; i++)
game.log("DEBUG >> StuntManager.onEventBoxExitCallback(): truckNum="+truckNum+", objInstance="+objInstance+", boxName="+boxName);
for (uint i = 0; i < this.stuntList.length(); i++)
{
StuntBuilder@ stunt = this.stuntList[i];
// Stunt begins when vehicle stops touching the starting box.
Expand All @@ -59,12 +65,13 @@ class StuntsManager
stunt.beginStunt(truckNum);
}
}
game.log("DEBUG << StuntManager.onEventBoxExitCallback()");
}

void onEventboxEnterCallback(int truckNum, int nodeNum, string objInstance, string boxName)
{
const int stuntCount = this.getStuntCount();
for (int i = 0; i < stuntCount; i++)
game.log("DEBUG >> StuntManager.onEventBoxEnterCallback(): truckNum="+truckNum+", nodeNum="+nodeNum+", objInstance="+objInstance+", boxName="+boxName);
for (uint i = 0; i < this.stuntList.length(); i++)
{
StuntBuilder@ stunt = this.stuntList[i];
// Stunt ends when vehicle touches the finish box.
Expand All @@ -74,15 +81,15 @@ class StuntsManager
&& boxName == stunt.endBoxName)
{
game.log("DEBUG: Stunt '" + stunt.stuntName + "' (ID: " + i + ") finished!");
stunt.isOngoing = false;
stunt.finishStunt();
}
}
game.log("DEBUG << StuntManager.onEventBoxEnterCallback()");
}

void frameStep(float dt)
{
const int stuntCount = this.getStuntCount();
for (int i = 0; i < stuntCount; i++)
for (int i = 0; i < this.stuntList.length(); i++)
{
StuntBuilder@ stunt = this.stuntList[i];
if (stunt.isOngoing)
Expand All @@ -97,6 +104,7 @@ class StuntsManager
*/
int addStunt(string stuntName, string startObj, string startBox, string endObj, string endBox)
{
game.log("DEBUG >> StuntsManager.addStunt()");
StuntBuilder b;
b.stuntName = stuntName;
b.startObjInstance = startObj;
Expand All @@ -105,14 +113,14 @@ class StuntsManager
b.endBoxName = endBox;

int stuntID = this.getNewStuntID();
this.stuntList[stuntID] = b;
game.log("DEBUG: StuntsManager.addStunt(): added stunt '"+stuntName+"' with ID " + stuntID + ", stuntCount=" + this.getStuntCount());
@this.stuntList[stuntID] = @b;
game.log("DEBUG << StuntsManager.addStunt(): added stunt '"+stuntName+"' with ID " + stuntID + ", stuntCount=" + this.stuntList.length());
return stuntID;
}

void deleteStunt(int stuntID)
{
const int stuntCount = this.getStuntCount();
const int stuntCount = this.stuntList.length();
if (stuntID > 0 && stuntID < stuntCount)
{
if (stuntID == stuntCount - 1)
Expand All @@ -122,22 +130,23 @@ class StuntsManager
}
}

int getStuntCount()
{
return int(this.stuntList.length());
}

private int getNewStuntID()
{
game.log("DEBUG >> StuntsManager.getNewStuntID(): stuntCount="+this.stuntList.length());
// try to recycle a stunt ID
for( int i = 0; i < this.getStuntCount(); i++ )
for( uint i = 0; i < this.stuntList.length(); i++ )
{
if( this.stuntList[i].awaitingRecycling )
return i;
{
game.log("DEBUG << StuntsManager.getNewStuntID(): recycling ID "+i+", stuntCount="+this.stuntList.length());
return int(i);
}
}
// resize list and return new ID
stuntList.resize(this.getStuntCount() + 1);
return this.getStuntCount();
int newID = int(this.stuntList.length());
stuntList.resize(this.stuntList.length() + 1);
game.log("DEBUG << StuntsManager.getNewStuntID(): new ID "+newID+", stuntCount="+this.stuntList.length());
return newID;
}
}

Expand Down

0 comments on commit 97e94bb

Please sign in to comment.