void AddRunwayCraters (Objective o, int f, int craters) { // Add a few linked craters // NOTE: These need to be deterministically generated int i,tp,rp; float x1,y1,x,y,xd,yd,r; int rwindex,runway = 0; ObjClassDataType *oc; // Find the runway header this feature belongs to oc = o->GetObjectiveClassData(); rwindex = oc->PtDataIndex; while (rwindex && !runway) { if (PtHeaderDataTable[rwindex].type == RunwayPt) { for (i=0; i<MAX_FEAT_DEPEND && !runway; i++) { if (PtHeaderDataTable[rwindex].features[i] == f) runway = rwindex; } } rwindex = PtHeaderDataTable[rwindex].nextHeader; } // Check for valid runway (could be a runway number or something) if (!runway) return; rp = GetFirstPt(runway); tp = rp + 1; TranslatePointData(o,rp,&xd,&yd); TranslatePointData(o,tp,&x1,&y1); xd -= x1; yd -= y1; // Seed the random number generator srand(o->Id().num_); for (i=0; i<craters; i++) { // Randomly place craters along the runway. r = ((float)(rand()%1000)) / 1000.0F; x = x1 + r*xd + (((float)(rand()%50)) / 50.0F); y = y1 + r*yd + (((float)(rand()%50)) / 50.0F); NewLinkedPersistantObject(MapVisId(VIS_CRATER2), o->Id(), f, x, y); #ifdef DEBUG Persistant_Runway_Craters++; #endif } }
int TaskForceClass::GetDeaggregationPoint (int slot, CampEntity *installation) { int pt=0,type; static int last_pt, index = 0; if (!*installation) { // We're looking for a new list, so clear statics last_pt = index = 0; // Check if we care about placement if (!Moving()) { // Find the appropriate installation GridIndex x,y; Objective o; GetLocation(&x,&y); o = FindNearestObjective (x,y,NULL,0); *installation = o; // Find the appropriate list if (o) { ObjClassDataType *oc = o->GetObjectiveClassData(); index = oc->PtDataIndex; while (index) { if (PtHeaderDataTable[index].type == DockListType) { // The first time we look, we just want to know if we have a list. // Return now. return index; } index = PtHeaderDataTable[index].nextHeader; } #ifdef DEBUG FILE *fp = fopen("PtDatErr.log","a"); if (fp) { char name[80]; o->GetName(name,79,FALSE); fprintf(fp, "Obj %s @ %d,%d: No header list of type %d.\n",name,x,y,DockListType); fclose(fp); } #endif } } } if (index) { // We have a list, and want to find the correct point UnitClassDataType *uc = GetUnitClassData(); VehicleClassDataType *vc = GetVehicleClassData(uc->VehicleType[slot]); // Check which type of point we're looking for // TODO: Check ship type here... // type = SmallDockPt; type = LargeDockPt; // Return the next point, if it's the base type // NOTE: Log error if we don't have enough points of this type if (last_pt) { last_pt = pt = GetNextPt(last_pt); #ifdef DEBUG if (!pt || PtDataTable[pt].type != type) { FILE *fp = fopen("PtDatErr.log","a"); if (fp) { char name[80]; GridIndex x,y; (*installation)->GetName(name,79,FALSE); (*installation)->GetLocation(&x,&y); fprintf(fp, "HeaderList %d (Obj %s @ %d,%d): Insufficient points of type %d.\n",index,name,x,y,type); fclose(fp); } } #endif return pt; } // Find one of the appropriate type pt = GetFirstPt(index); while (pt) { if (PtDataTable[pt].type == type) { last_pt = pt; return pt; } pt = GetNextPt(pt); } #ifdef DEBUG FILE *fp = fopen("PtDatErr.log","a"); if (fp) { char name[80]; GridIndex x,y; (*installation)->GetName(name,79,FALSE); (*installation)->GetLocation(&x,&y); fprintf(fp, "HeaderList %d (Obj %s @ %d,%d): No points of type %d.\n",index,name,x,y,type); fclose(fp); } #endif } return pt; }