Thief 2/Source Code
From SDA Knowledge Base
Contents
Potions
Slow-fall
/* Potion's effect is to reduce gravity on the imbiber to 50%.
Also reduces movement speed by 50%, keeping jump distance about
the same. Only supported for player-character imbiber.
*/
BEGIN_SCRIPT(LoGravPotion,TimedPotion)
METHODS:
METHOD void PotionEffect(object imbiber, boolean start)
{
if(!Object.InheritsFrom(imbiber,Object.Named("Avatar")))
return;
if(start)
{
vector vel;
// Arrest downward velocity by 50%. If you'd been at 50%
// gravity all along, you'd actually only be at 30% less
// velocity at the same depth (a factory of 1/root(2)).
// This will then tend to encourage use of the potion in
// mid-fall, which sounds like fun. -TJS
Physics.GetVelocity(imbiber,vel);
if(vel.z<0) vel.z/=2;
Physics.SetVelocity(imbiber,vel);
DrkInv.AddSpeedControl("LoGrav",0.5,1.0);
Physics.SetGravity(imbiber,0.50);
}
else
{
Physics.SetGravity(imbiber,1.00);
DrkInv.RemoveSpeedControl("LoGrav");
}
}
END_SCRIPT(LoGravPotion)
Movement
Setting Velocity
This is what causes drinking slow-fall potions to free you from being stuck.
STDMETHOD(SetVelocity)(object obj, const vector ref vel)
{
// Setting velocities from scripts wants to be initially clear from the
// effects of friction, so we break all contacts.
cPhysModel *pModel = g_PhysModels.GetActive(obj);
if (pModel)
{
for (int i=0; i<pModel->NumSubModels(); i++)
{
pModel->DestroyAllTerrainContacts(i);
DestroyAllObjectContacts(obj, i, pModel);
}
}
PhysSetVelocity(obj, (mxs_vector*)&vel);
return S_OK;
}
Calling DestroyAllTerrainContacts also calls another method that makes you fall off any ropes.
Mission-specific
Mission 6 Key Location
The mission source code basically takes a random number (and RNG seed is based on system uptime in miliseconds): Code (MISS6.SCR):
#define KEYPATHS 9
[...]
SetData("PathNumber",Data.RandInt(1,KEYPATHS)); //which key we're using.
[...]
SetupLocation();
//setup the location, if we are the starting
//point. This allows all sorts of wholesome
//linky goodness.
There is also a game config cheat parameter to fix the key location to a specific one.