void Truck::Move() { if (!path.Moving()) SelectAnimation(IDLE); else SelectAnimation(DOWN); // Move with the path position = original_pos + path.GetCurrentSpeed(); }
virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) { Init(paramNode); u32 oldSeed = GetActorSeed(); SerializeCommon(deserialize); // If we serialized a different seed, reload actor if (oldSeed != GetActorSeed()) ReloadActor(); fixed repeattime = m_AnimSyncRepeatTime; // save because SelectAnimation overwrites it if (m_AnimRunThreshold.IsZero()) SelectAnimation(m_AnimName, m_AnimOnce, m_AnimSpeed, m_SoundGroup); else SelectMovementAnimation(m_AnimRunThreshold); SetAnimationSyncRepeat(repeattime); if (m_Unit) { CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId()); if (cmpOwnership) m_Unit->GetModel().SetPlayerID(cmpOwnership->GetOwner()); } }
virtual void Init(const CParamNode& paramNode) { m_PreviouslyRendered = false; m_Unit = NULL; m_Visibility = ICmpRangeManager::VIS_HIDDEN; m_R = m_G = m_B = fixed::FromInt(1); m_ConstructionPreview = paramNode.GetChild("ConstructionPreview").IsOk(); m_ConstructionProgress = fixed::Zero(); m_Seed = GetEntityId(); if (paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk()) m_ActorName = paramNode.GetChild("FoundationActor").ToString(); else m_ActorName = paramNode.GetChild("Actor").ToString(); InitModel(paramNode); // We need to select animation even if graphics are disabled, as this modifies serialized state SelectAnimation("idle", false, fixed::FromInt(1), L""); m_NeedsInterpolation = true; m_PositionChanged = true; }
virtual void Init(const CParamNode& paramNode) { m_PreviouslyRendered = false; m_Unit = NULL; m_Visibility = ICmpRangeManager::VIS_HIDDEN; m_R = m_G = m_B = fixed::FromInt(1); if (!GetSimContext().HasUnitManager()) return; // do nothing further if graphics are disabled // TODO: we should do some fancy animation of under-construction buildings rising from the ground, // but for now we'll just use the foundation actor and ignore the normal one if (paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk()) m_ActorName = paramNode.GetChild("FoundationActor").ToString(); else m_ActorName = paramNode.GetChild("Actor").ToString(); std::set<CStr> selections; m_Unit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections); if (m_Unit) { CModelAbstract& model = m_Unit->GetModel(); if (model.ToCModel()) { u32 modelFlags = 0; if (paramNode.GetChild("SilhouetteDisplay").ToBool()) modelFlags |= MODELFLAG_SILHOUETTE_DISPLAY; if (paramNode.GetChild("SilhouetteOccluder").ToBool()) modelFlags |= MODELFLAG_SILHOUETTE_OCCLUDER; CmpPtr<ICmpVision> cmpVision(GetSimContext(), GetEntityId()); if (cmpVision && cmpVision->GetAlwaysVisible()) modelFlags |= MODELFLAG_IGNORE_LOS; model.ToCModel()->AddFlagsRec(modelFlags); } // Initialize the model's selection shape descriptor. This currently relies on the component initialization order; the // Footprint component must be initialized before this component (VisualActor) to support the ability to use the footprint // shape for the selection box (instead of the default recursive bounding box). See TypeList.h for the order in // which components are initialized; if for whatever reason you need to get rid of this dependency, you can always just // initialize the selection shape descriptor on-demand. InitSelectionShapeDescriptor(model, paramNode); m_Unit->SetID(GetEntityId()); } SelectAnimation("idle", false, fixed::FromInt(1), L""); }
virtual void Init(const CParamNode& paramNode) { m_Unit = NULL; if (!GetSimContext().HasUnitManager()) return; // do nothing if graphics are disabled // TODO: we should do some fancy animation of under-construction buildings rising from the ground, // but for now we'll just use the foundation actor and ignore the normal one if (paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk()) m_ActorName = paramNode.GetChild("FoundationActor").ToString(); else m_ActorName = paramNode.GetChild("Actor").ToString(); m_R = m_G = m_B = fixed::FromInt(1); std::set<CStr> selections; m_Unit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections); if (!m_Unit) { // The error will have already been logged return; } u32 modelFlags = 0; if (paramNode.GetChild("SilhouetteDisplay").ToBool()) modelFlags |= MODELFLAG_SILHOUETTE_DISPLAY; if (paramNode.GetChild("SilhouetteOccluder").ToBool()) modelFlags |= MODELFLAG_SILHOUETTE_OCCLUDER; if (m_Unit->GetModel().ToCModel()) m_Unit->GetModel().ToCModel()->AddFlagsRec(modelFlags); m_Unit->SetID(GetEntityId()); SelectAnimation("idle", false, 0.f, L""); }
void Soldier1::Move() { if (subtype == 21){ if (App->player->position.x < 120) AI.x -= 0.3f; else AI.x += 0.3f; } float angle, dx, dy; int player_position_x, player_position_y; player_position_x = App->player->position.x; player_position_y = App->player->position.y; dx = float(player_position_x - position.x); dy = float(player_position_y - position.y); angle = atan2(dy, dx) * 180 / PI; //THE ANGLE IS INVERTED //bot right quadrant if (dx > 0 && dy > 0 && angle > 0 && angle<11.25) { direction = RIGHT; SelectAnimation(direction); } else if (dx > 0 && dy > 0 && angle>11.25 && angle < 33.75) { direction = RIGHT_M_BOT; SelectAnimation(direction); } else if (dx > 0 && dy > 0 && angle>33.75 && angle < 56.25) { direction = DOWN_RIGHT; SelectAnimation(direction); } else if (dx > 0 && dy > 0 && angle>56.25 && angle < 78.25) { direction = RIGHT_B_BOT; SelectAnimation(direction); } else if (dx > 0 && dy > 0 && angle>78.25 && angle < 90) { direction = DOWN; SelectAnimation(direction); } //bot left quadrant else if (dx < 0 && (angle>168.75)) { direction = LEFT; SelectAnimation(direction); } else if (dx < 0 && dy>0 && angle<168.75 && angle>146.25) { direction = LEFT_M_DOWN; SelectAnimation(direction); } else if (dx < 0 && (angle<146.25) && (angle>123.75)) { direction = DOWN_LEFT; SelectAnimation(direction); } else if (dx < 0 && dy>0 && angle < 123.75 && angle >101.75) { direction = LEFT_B_DOWN; SelectAnimation(direction); } else if (dx < 0 && dy>0 && angle<101.75 && angle > 90) { direction = DOWN; SelectAnimation(direction); } //top left quadrant else if (dx > 0 && angle>0 && angle<11.25) { direction = LEFT; SelectAnimation(direction); } else if (dx < 0 && dy < 0 && angle>-168.75 && angle < -146.25) { direction = LEFT_M_UP; SelectAnimation(direction); } else if (dx < 0 && dy < 0 && angle>-146.25 && angle < -123.75) { direction = UP_LEFT; SelectAnimation(direction); } else if (dx < 0 && dy < 0 && angle>-123.75 && angle < -101.75) { direction = LEFT_U_UP; SelectAnimation(direction); } else if (dx < 0 && dy < 0 && angle>-101.75 && angle < -90) { direction = UP; SelectAnimation(direction); } //top right quadrant else if (dx>0 && dy<0 && angle<-0.1 && angle>-11.25) { direction = RIGHT; SelectAnimation(direction); } else if (dx>0 && dy<0 && angle < -11.25 && angle > -33.75) { direction = RIGHT_M_UP; SelectAnimation(direction); } else if (dx>0 && dy<0 && angle < -33.75 && angle > -56.25) { direction = UP_RIGHT; SelectAnimation(direction); } else if (dx>0 && dy<0 && angle < -56.25 && angle > -78.25) { direction = RIGHT_U_UP; SelectAnimation(direction); } else if (dx>0 && dy<0 && angle < -78.25 && angle > -89.1) { direction = UP; SelectAnimation(direction); } // Move with the path position = original_pos + path.GetCurrentSpeed() + AI; }