//------------------------------------------------------------------------ void CVehicleMovementStdBoat::PostPhysicalize() { CVehicleMovementBase::PostPhysicalize(); // removed fetching the centre of mass here; with MT physics it is not guaranteed to be correct // at this point. Since boats only have one part with mass (the mass box) using the centre of that bbox is fine. if (GetMovementType() == eVMT_Sea) { pe_params_foreign_data pfd; pfd.iForeignFlagsOR = PFF_UNIMPORTANT; GetPhysics()->SetParams(&pfd); } }
int TaskForceClass::Reaction (CampEntity e, int knowledge, float range) { int score = 0, enemy_threat_bonus = 1; CampEntity et = NULL; MoveType tmt,omt; if (!e) return 0; // Some basic info on us. omt = GetMovementType(); tmt = e->GetMovementType(); // Aircraft on ground are ignored (technically, we could shoot at them.. but..) if (e->IsFlight() && !((Flight)e)->Moving()) return 0; // Score their threat to us if (knowledge & FRIENDLY_DETECTED) enemy_threat_bonus++; if (knowledge & FRIENDLY_IN_RANGE) enemy_threat_bonus += 2; et = ((Unit)e)->GetCampTarget(); // All units score vs enemy engaged with this unit if (et == this) score += e->GetAproxHitChance(omt,0)/5 * enemy_threat_bonus; // Bonus if we can shoot them if (knowledge & ENEMY_IN_RANGE) score += GetAproxHitChance(tmt,FloatToInt32(range/2.0F))/5; // Added bonus for them attacking if (et && (tmt == Air || tmt == LowAir)) score += GetAproxHitChance(tmt,0)/5 * enemy_threat_bonus; return score; }
int CObject::Create (ubyte nType, ubyte nId, short nCreator, short nSegment, const CFixVector& vPos, const CFixMatrix& mOrient, fix xSize, ubyte cType, ubyte mType, ubyte rType) { #if DBG if (nType == OBJ_WEAPON) { nType = nType; if ((nCreator >= 0) && (OBJECTS [nCreator].info.nType == OBJ_ROBOT)) nType = nType; if (nId == FLARE_ID) nType = nType; if (gameData.objs.bIsMissile [(int) nId]) nType = nType; } else if (nType == OBJ_ROBOT) { #if 0 if (ROBOTINFO ((int) nId).bossFlag && (BOSS_COUNT >= MAX_BOSS_COUNT)) return -1; #endif } else if (nType == OBJ_HOSTAGE) nType = nType; else if (nType == OBJ_FIREBALL) nType = nType; else if (nType == OBJ_REACTOR) nType = nType; else if (nType == OBJ_DEBRIS) nType = nType; else if (nType == OBJ_MARKER) nType = nType; else if (nType == OBJ_PLAYER) nType = nType; else if (nType == OBJ_POWERUP) nType = nType; #endif SetSegment (FindSegByPos (vPos, nSegment, 1, 0)); if ((Segment () < 0) || (Segment () > gameData.segs.nLastSegment)) return -1; if (nType == OBJ_DEBRIS) { if (gameData.objs.nDebris >= gameStates.render.detail.nMaxDebrisObjects) return -1; } // Zero out object structure to keep weird bugs from happening in uninitialized fields. m_nId = OBJ_IDX (this); SetSignature (gameData.objs.nNextSignature++); SetType (nType); SetId (nId); SetLastPos (vPos); SetPos (&vPos); SetSize (xSize); SetCreator ((sbyte) nCreator); SetOrient (&mOrient); SetControlType (cType); SetMovementType (mType); SetRenderType (rType); SetContainsType (-1); SetLifeLeft ( ((gameData.app.nGameMode & GM_ENTROPY) && (nType == OBJ_POWERUP) && (nId == POW_HOARD_ORB) && (extraGameInfo [1].entropy.nVirusLifespan > 0)) ? I2X (extraGameInfo [1].entropy.nVirusLifespan) : IMMORTAL_TIME); SetAttachedObj (-1); m_xCreationTime = gameData.time.xGame; #if 0 if (GetControlType () == CT_POWERUP) CPowerupInfo::SetCount (1); // Init physics info for this CObject if (GetMovementType () == MT_PHYSICS) m_vStartVel.SetZero (); if (GetRenderType () == RT_POLYOBJ) CPolyObjInfo::SetTexOverride (-1); if (GetType () == OBJ_WEAPON) { CPhysicsInfo::SetFlags (CPhysInfo.GetFlags () | WI_persistent (m_info.nId) * PF_PERSISTENT); CLaserInfo::SetCreationTime (gameData.time.xGame); CLaserInfo::SetLastHitObj (0); CLaserInfo::SetScale (I2X (1)); } else if (GetType () == OBJ_DEBRIS) gameData.objs.nDebris++; if (GetControlType () == CT_POWERUP) CPowerupInfo::SetCreationTime (gameData.time.xGame); else if (GetControlType () == CT_EXPLOSION) { CAttachedInfo::SetPrev (-1); CAttachedInfo::SetNext (-1); CAttachedInfo::SetParent (-1); } #endif Link (); LinkToSeg (nSegment); return m_nId; }
void Move::Spin() { if(!active) return; // Do some look-ahead work, if there's any to do DoLookAhead(); // If there's space in the DDA ring, and there are completed // moves in the look-ahead ring, transfer them. if(!DDARingFull()) { LookAhead* nextFromLookAhead = LookAheadRingGet(); if(nextFromLookAhead != NULL) { if(!DDARingAdd(nextFromLookAhead)) platform->Message(HOST_MESSAGE, "Can't add to non-full DDA ring!\n"); // Should never happen... } } // If we either don't want to, or can't, add to the look-ahead ring, go home. if(addNoMoreMoves || LookAheadRingFull()) { platform->ClassReport("Move", longWait); return; } // If there's a G Code move available, add it to the look-ahead // ring for processing. bool checkEndStopsOnNextMove; if(gCodes->ReadMove(nextMove, checkEndStopsOnNextMove)) { Transform(nextMove); currentFeedrate = nextMove[DRIVES]; // Might be G1 with just an F field for(int8_t drive = 0; drive < DRIVES; drive++) nextMachineEndPoints[drive] = LookAhead::EndPointToMachine(drive, nextMove[drive]); int8_t movementType = GetMovementType(lastMove->MachineEndPoints(), nextMachineEndPoints); // Throw it away if there's no real movement. if(movementType == noMove) { platform->ClassReport("Move", longWait); return; } // Real move - record its feedrate with it, not here. currentFeedrate = -1.0; // Promote minimum feedrates if(movementType & xyMove) nextMove[DRIVES] = fmax(nextMove[DRIVES], platform->InstantDv(X_AXIS)); else if(movementType & eMove) nextMove[DRIVES] = fmax(nextMove[DRIVES], platform->InstantDv((AXES+gCodes->GetSelectedHead()))); else nextMove[DRIVES] = fmax(nextMove[DRIVES], platform->InstantDv(Z_AXIS)); // Restrict maximum feedrates; assumes xy overrides e overrides z FIXME?? if(movementType & xyMove) nextMove[DRIVES] = fmin(nextMove[DRIVES], platform->MaxFeedrate(X_AXIS)); // Assumes X and Y are equal. FIXME? else if(movementType & eMove) nextMove[DRIVES] = fmin(nextMove[DRIVES], platform->MaxFeedrate(AXES+gCodes->GetSelectedHead())); // Fixed else // Must be z nextMove[DRIVES] = fmin(nextMove[DRIVES], platform->MaxFeedrate(Z_AXIS)); if(!LookAheadRingAdd(nextMachineEndPoints, nextMove[DRIVES], 0.0, checkEndStopsOnNextMove, movementType)) platform->Message(HOST_MESSAGE, "Can't add to non-full look ahead ring!\n"); // Should never happen... } platform->ClassReport("Move", longWait); }
void BrigadeClass::SetUnitOrders (int neworders, VU_ID oid) { Objective o,so; GridIndex x,y,dx,dy; Unit e; SetOrdered(1); SetUnitTactic(0); o = FindObjective(oid); #ifdef DEBUG if (gDumping) { FILE *fp; int id1; char buffer[256]; char name1[80],name2[80],timestr[80]; sprintf(buffer,"campaign\\save\\dump\\%d.BRI",GetCampID()); fp = fopen(buffer,"a"); if (fp) { if (o) { o->GetName(name1,79,FALSE); id1 = o->GetCampID(); } else { sprintf(name1,"NONE"); id1 = 0; } GetName(name2,79,FALSE); GetTimeString(TheCampaign.CurrentTime,timestr); sprintf(buffer,"%s (%d) ordered to %s %s (%d) @ %s.\n",name2,GetCampID(),OrderStr[neworders],name1,id1,timestr); fprintf(fp,buffer); fclose(fp); } else gDumping = 0; } #endif if (!o) return; o->GetLocation(&dx,&dy); GetLocation(&x,&y); if ((x != dx || y != dy) && GetMovementType() != NoMove) { SetMoving(1); SetUnitDestination(dx,dy); } SetTempDest(0); if (neworders == GetOrders() && oid == GetUnitObjectiveID()) return; DisposeWayPoints(); SetUnitObjective(oid); GroundUnitClass::SetUnitOrders(neworders); // Reset component ordered state e = GetFirstUnitElement(); while (e) { e->SetAssigned(0); e = GetNextUnitElement(); } // If this is near the front, send a low priority request for an enemy recon patrol if (o->IsNearfront()) { MissionRequestClass mis; mis.tot = Camp_GetCurrentTime() + (rand()%MIN_TASK_GROUND + 30) * CampaignMinutes; mis.vs = GetTeam(); mis.tot_type = TYPE_NE; o->GetLocation(&mis.tx,&mis.ty); mis.targetID = Id(); mis.mission = AMIS_RECONPATROL; mis.roe_check = ROE_AIR_OVERFLY; mis.RequestEnemyMission(); } // Let's make sure our objective tree jives with our assignment if (o->IsSecondary()) { so = o->GetObjectiveParent(); if (so) SetUnitPrimaryObj(so->Id()); SetUnitSecondaryObj(o->Id()); } else if (o->IsPrimary()) { SetUnitPrimaryObj(o->Id()); SetUnitSecondaryObj(o->Id()); } else { so = o->GetObjectiveParent(); if (so) { SetUnitSecondaryObj(so->Id()); o = so->GetObjectiveParent(); if (o) SetUnitPrimaryObj(o->Id()); } } }