Skip to content

Commit

Permalink
Merge pull request #40 from Gh0stblade/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
Gh0stBlade committed Aug 8, 2015
2 parents 64dec32 + e685301 commit 7d67e43
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 15 deletions.
35 changes: 29 additions & 6 deletions scripts/entity/entity_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,8 @@ function midastouch_init(id) -- Midas gold touch
setEntityTypeFlag(id, ENTITY_TYPE_GENERIC);

entity_funcs[id].onLoop = function(object_id)
if(getEntityDistance(player, object_id) < 1024.0) then
local lara_anim, frame, count = getEntityAnim(player);
local lara_sector = getEntitySectorIndex(player);
local hand_sector = getEntitySectorIndex(object_id);

if((lara_sector == hand_sector) and (getEntityMoveType(player) == MOVE_ON_FLOOR) and (getEntityAnim(player) ~= 50)) then
if(sameSector(player, object_id)) then
if((getEntityMoveType(player) == MOVE_ON_FLOOR) and (getEntityAnim(player) ~= 50)) then
setCharacterParam(player, PARAM_HEALTH, 0);
setEntityAnim(player, 1, 0, 5);
disableEntity(object_id);
Expand Down Expand Up @@ -1744,6 +1740,33 @@ function damocles_init(id) -- Sword of Damocles
end
end

function tightrope_init(id)

setEntityTypeFlag(id, ENTITY_TYPE_GENERIC);

entity_funcs[id].onLoop = function(object_id)

local dist_to_Lara = getEntityDistance(player, object_id);

if(dist_to_Lara < 512.0) then
local orient = getEntityOrientation(object_id, player);

if(getActionState(ACT_ACTION) and ((orient > 320.0) or (orient < 40.0))) then
if(getEntityState(player) == 2) then
setEntityPos(player, getEntityPos(object_id));
rotateEntity(player,180);
moveEntityLocal(player,0,384,0);
setEntityState(player, 124);
end;
elseif((orient < 220.0) and (orient > 140.0)) then
if(getEntityState(player) == 121) then setEntityState(player, 125) end;
end;
end;
end;

prepareEntity(id);
end

function snake_init(id)

setEntityTypeFlag(id, ENTITY_TYPE_ACTOR);
Expand Down
2 changes: 1 addition & 1 deletion scripts/entity/entity_properties.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ tr5_entity_tbl[151] = {coll = COLLISION_TYPE_KINEMATIC, shape = COLLISION_SHAPE_
tr5_entity_tbl[152] = {coll = COLLISION_TYPE_KINEMATIC, shape = COLLISION_SHAPE_BOX}; -- Security camera board

tr5_entity_tbl[153] = {coll = COLLISION_TYPE_NONE, shape = COLLISION_SHAPE_BOX, hide = true}; -- Motion sensor
tr5_entity_tbl[154] = {coll = COLLISION_TYPE_NONE, shape = COLLISION_SHAPE_BOX, hide = true}; -- Tight rope
tr5_entity_tbl[154] = {coll = COLLISION_TYPE_NONE, shape = COLLISION_SHAPE_BOX, hide = true, func = "tightrope"}; -- Tight rope

tr5_entity_tbl[155] = {coll = COLLISION_TYPE_KINEMATIC, shape = COLLISION_SHAPE_TRIMESH}; -- Parallel bars

Expand Down
2 changes: 1 addition & 1 deletion scripts/staticmesh/staticmesh_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static_tbl = {}; -- Define static mesh property table.

function getStaticMeshProperties(id)
if((static_tbl == nil) or (static_tbl[id] == nil)) then
return COLLISION_TYPE_STATIC, COLLISION_SHAPE_BOX, nil;
return -1;
else
local coll, shape, hide;
if(static_tbl[id].hide ~= nil) then hide = static_tbl[id].hide else hide = false end;
Expand Down
131 changes: 131 additions & 0 deletions src/anim_state_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ void ent_to_monkey_swing(Character* ent, SSAnimation* ss_anim, int state)
}
}

void ent_to_tightrope(Character* ent, SSAnimation* ss_anim, int state)
{
if(state == ENTITY_ANIM_NEWANIM)
{
ent->m_moveType = MoveType::Climbing;
ent->ghostUpdate();
ss_anim->onFrame = nullptr;
}
}

void ent_from_tightrope(Character* ent, SSAnimation* ss_anim, int state)
{
if(state == ENTITY_ANIM_NEWANIM)
{
ent->m_moveType = MoveType::OnFloor;
ent->ghostUpdate();
ss_anim->onFrame = nullptr;
}
}

void ent_crawl_to_climb(Character* ent, SSAnimation* ss_anim, int state)
{
if(state == ENTITY_ANIM_NEWANIM)
Expand Down Expand Up @@ -2987,6 +3007,117 @@ int State_Control_Lara(Character* character, struct SSAnimation *ss_anim)
}
break;

case TR_STATE_LARA_TIGHTROPE_ENTER:
cmd->rot[0] = 0.0;
character->m_bt.no_fix_all = true;
character->m_dirFlag = ENT_MOVE_FORWARD;
ss_anim->onFrame = ent_to_tightrope;
ss_anim->next_state = TR_STATE_LARA_TIGHTROPE_IDLE;
break;

case TR_STATE_LARA_TIGHTROPE_EXIT:
cmd->rot[0] = 0.0;
character->m_bt.no_fix_all = true;
character->m_dirFlag = ENT_MOVE_FORWARD;
ss_anim->onFrame = ent_from_tightrope;
ss_anim->next_state = TR_STATE_LARA_STOP;
break;

case TR_STATE_LARA_TIGHTROPE_IDLE:
cmd->rot[0] = 0.0;

if(ss_anim->current_animation == TR_ANIMATION_LARA_TIGHTROPE_STAND)
{
if(character->m_response.lean == LeanType::Left)
{
ss_anim->next_state = TR_STATE_LARA_TIGHTROPE_BALANCING_LEFT;
character->m_response.lean = LeanType::None;
break;
}
else if(character->m_response.lean == LeanType::Right)
{
ss_anim->next_state = TR_STATE_LARA_TIGHTROPE_BALANCING_RIGHT;
character->m_response.lean = LeanType::None;
break;
}
else if(last_frame)
{
uint16_t chance_to_fall = rand() % 0x7FFF;

if(chance_to_fall > 0x5FFF)
ss_anim->next_state = TR_STATE_LARA_TIGHTROPE_BALANCING_LEFT;
else if(chance_to_fall < 0x2000)
ss_anim->next_state = TR_STATE_LARA_TIGHTROPE_BALANCING_RIGHT;
}
}

if((cmd->roll) || (cmd->move[0] == -1))
{
character->setAnimation(TR_ANIMATION_LARA_TIGHTROPE_TURN, 0);
character->m_dirFlag = ENT_MOVE_FORWARD;
}
else if(cmd->move[0] == 1)
{
ss_anim->next_state = TR_STATE_LARA_TIGHTROPE_FORWARD;
}
break;

case TR_STATE_LARA_TIGHTROPE_FORWARD:
cmd->rot[0] = 0.0;
character->m_dirFlag = ENT_MOVE_FORWARD;

if(cmd->move[0] != 1)
{
ss_anim->next_state = TR_STATE_LARA_TIGHTROPE_IDLE;
}
else
{
uint16_t chance_to_unbal = rand() % 0x7FFF;
if(chance_to_unbal < 0x00FF)
{
ss_anim->next_state = TR_STATE_LARA_TIGHTROPE_IDLE;

if(chance_to_unbal > 0x007F)
character->m_response.lean = LeanType::Left;
else
character->m_response.lean = LeanType::Right;
}
}
break;

case TR_STATE_LARA_TIGHTROPE_BALANCING_RIGHT:
cmd->rot[0] = 0.0;

if((ss_anim->current_animation == TR_ANIMATION_LARA_TIGHTROPE_FALL_RIGHT) && (last_frame))
{
character->m_moveType = MoveType::FreeFalling;
character->m_transform.getOrigin() += character->m_transform.getBasis() * btVector3(256.0, 192.0, -640.0);
character->setAnimation(TR_ANIMATION_LARA_FREE_FALL_LONG, 0);
}
else if((ss_anim->current_animation == TR_ANIMATION_LARA_TIGHTROPE_LOOSE_RIGHT) && (ss_anim->current_frame >= 15) && (cmd->move[1] == -1))
{
// MAGIC: mirroring animation position.
character->setAnimation(TR_ANIMATION_LARA_TIGHTROPE_RECOVER_RIGHT, 30-ss_anim->current_frame);
}
break;

case TR_STATE_LARA_TIGHTROPE_BALANCING_LEFT:
cmd->rot[0] = 0.0;

if((ss_anim->current_animation == TR_ANIMATION_LARA_TIGHTROPE_FALL_LEFT) && (last_frame))
{
character->m_moveType = MoveType::FreeFalling;
character->setAnimation(TR_ANIMATION_LARA_FREE_FALL_LONG, 0);
character->m_transform.getOrigin() += character->m_transform.getBasis() * btVector3(-256.0, 192.0, -640.0);
}
else if((ss_anim->current_animation == TR_ANIMATION_LARA_TIGHTROPE_LOOSE_LEFT) && (ss_anim->current_frame >= 15) && (cmd->move[1] == 1))
{
// MAGIC: mirroring animation position.
character->setAnimation(TR_ANIMATION_LARA_TIGHTROPE_RECOVER_LEFT, 30-ss_anim->current_frame);
}
break;


/*
* intermediate animations are processed automatically.
*/
Expand Down
33 changes: 27 additions & 6 deletions src/character_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,10 @@ int Character::monkeyClimbing()
auto& pos = m_transform.getOrigin();

m_speed[2] = 0.0;

m_response.slide = SlideType::None;
m_response.lean = LeanType::None;

m_response.horizontal_collide = 0x00;
m_response.vertical_collide = 0x00;

Expand Down Expand Up @@ -1251,7 +1254,6 @@ int Character::monkeyClimbing()
{
//dir_flag = ENT_MOVE_FORWARD;
}
m_response.slide = SlideType::None;

m_speed = spd;
move = spd * engine_frame_time;
Expand Down Expand Up @@ -1391,6 +1393,7 @@ int Character::climbing()
}

m_response.slide = SlideType::None;

m_speed = spd;
move = spd * engine_frame_time;

Expand Down Expand Up @@ -1423,8 +1426,10 @@ int Character::moveUnderWater()
}

m_response.slide = SlideType::None;
m_response.lean = LeanType::None;

m_response.horizontal_collide = 0x00;
m_response.vertical_collide = 0x00;
m_response.vertical_collide = 0x00;

// Calculate current speed.

Expand Down Expand Up @@ -1481,8 +1486,10 @@ int Character::moveOnWater()
auto& pos = m_transform.getOrigin();

m_response.slide = SlideType::None;
m_response.lean = LeanType::None;

m_response.horizontal_collide = 0x00;
m_response.vertical_collide = 0x00;
m_response.vertical_collide = 0x00;

m_angles[0] += inertiaAngular(1.0, ROT_SPEED_ONWATER, 0);
m_angles[1] = 0.0;
Expand Down Expand Up @@ -2288,10 +2295,22 @@ void Character::processSectorImpl()
if(lowest_sector->flags & SECTOR_FLAG_DEATH)
{
if((m_moveType == MoveType::OnFloor) ||
(m_moveType == MoveType::Underwater) ||
(m_moveType == MoveType::Wade) ||
(m_moveType == MoveType::OnWater) ||
(m_moveType == MoveType::Wade) ||
(m_moveType == MoveType::Quicksand))
{
if(m_heightInfo.floor_hit)
{
EngineContainer* cont = static_cast<EngineContainer*>(m_heightInfo.floor_obj->getUserPointer());

if((cont != nullptr) && (cont->object_type == OBJECT_ROOM_BASE))
{
setParam(PARAM_HEALTH, 0.0);
m_response.killed = true;
}
}
}
else if((m_moveType == MoveType::Underwater) ||
(m_moveType == MoveType::OnWater))
{
setParam(PARAM_HEALTH, 0.0);
m_response.killed = true;
Expand Down Expand Up @@ -2330,7 +2349,9 @@ void Character::jump(btScalar v_vertical, btScalar v_horizontal)
}

m_response.vertical_collide = 0x00;

m_response.slide = SlideType::None;
m_response.lean = LeanType::None;

// Jump speed should NOT be added to current speed, as native engine
// fully replaces current speed with jump speed by anim command.
Expand Down
8 changes: 8 additions & 0 deletions src/character_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ enum class StepType
UpImpossible //!< too big height, no one ways here, or phantom case
};

enum class LeanType
{
None,
Left,
Right
};

inline constexpr bool isLittleStep(StepType type)
{
return type >= StepType::DownLittle && type <= StepType::UpLittle;
Expand Down Expand Up @@ -272,6 +279,7 @@ struct CharacterResponse
int8_t horizontal_collide = 0;
//int8_t step_up;
SlideType slide = SlideType::None;
LeanType lean = LeanType::None;
};

struct CharacterParam
Expand Down
11 changes: 10 additions & 1 deletion src/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ void Res_GenEntityFunctions(std::map<uint32_t, std::shared_ptr<Entity> > &entiti

void Res_SetStaticMeshProperties(std::shared_ptr<StaticMesh> r_static)
{
lua::tie(r_static->self->collision_type, r_static->self->collision_shape, r_static->hide) = level_script.call("getStaticMeshProperties", r_static->object_id);
lua::Integer _collision_type, _collision_shape, _hide;
lua::tie(_collision_type, _collision_shape, _hide) = level_script.call("getStaticMeshProperties", r_static->object_id);

if(_collision_type > 0)
{
r_static->self->collision_type = _collision_type;
r_static->self->collision_shape = _collision_shape;
r_static->hide = _hide;
}
}

/*
Expand Down Expand Up @@ -1959,6 +1967,7 @@ void TR_GenRoom(size_t room_index, std::shared_ptr<Room>& room, World *world, cl
else
{
r_static->self->collision_type = COLLISION_TYPE_STATIC;
r_static->self->collision_shape = COLLISION_SHAPE_BOX_BASE;
}

// Set additional static mesh properties from level script override.
Expand Down
Loading

0 comments on commit 7d67e43

Please sign in to comment.