int destruction(int solid, int gap){
int ffplanpos=-1;
int i, j=-1;
int sum=0;
asteroid_t *planf = calloc(1, sizeof(asteroid_t));
asteroid_t *f=NULL;
plansys_t *p=NULL;
asteroid_t *next=NULL;
for(i=0; i<Sfreep; i++){
p=StarS[i].plasy;
while (p != NULL && p->solid != solid){
p=p->next;
}
if(p != NULL && p->solid == solid){
j=i;
}
}
if(j == -1){
return -1;
}
p=StarS[j].plasy;
if(p == NULL){
printf("The planetary system with identifier %d couldn't be found\n", solid);
return -1;
}
if(p->asteroids == NULL){
printf("The planetary system doesn't contain any asteroids\n");
return -1;
}
f=p->asteroids;
while(sum<gap && f != NULL){
sum=sum+f->gap;
next=f->next;
free(f);
f = next;
}
p->asteroids = f;
if (f != NULL) {
f->prev=NULL;
}
i=0;
while(i<max && StarS[j].ffplan[i].fp != INT_MAX){
i=i+1;
}
ffplanpos=i;
if(ffplanpos == -1){
return -1;
}
StarS[j].ffplan[ffplanpos].fp=solid;
if(f != NULL){
planf->as=f->as;
planf->gap=0;
planf->next=NULL;
planf->prev=NULL; f=f->next;
while(f != NULL){
if (StarS[j].ffplan[ffplanpos].ff == NULL) {
StarS[j].ffplan[ffplanpos].ff = planf;
} else {
asteroid_t *last = StarS[j].ffplan[ffplanpos].ff;
while (last->next != NULL) {
last = last->next;
}
last->next = planf;
}
f=f->next;
}
}
printf("\n\nPlanet Systems = ");
while(StarS[j].plasy != NULL){
printf(" %d ", StarS[j].plasy->solid);
StarS[j].plasy=StarS[j].plasy->next;
}
printf("\n\nFree-floatingM = ");
for(i=0; i<ffplanpos; i++){
printf(" %d ", StarS[j].ffplan[i].fp);
}
printf("\n\nFree-floating planets = ");
for(i=0; i<=ffplanpos; i++){
while(StarS[j].ffplan[i].ff != NULL){
printf(" %d ", StarS[j].ffplan[i].ff->as);
StarS[j].ffplan[i].ff=StarS[j].ffplan[i].ff->next;
}
}
return 0;
}