Example #1
0
int Structure::Place(Cell *targ)  {
  int alt=-100000, malt = 0;
  if(stgr[struct_type][material][2][0][0] == NULL)  return 0;
  switch(struct_type)  {
    case(STRUCT_RAMP):
    case(STRUCT_WALL):  {
      if(targ->Terrain() ==TERRAIN_LOWWATER || targ->Terrain() ==TERRAIN_WATER
	|| targ->Terrain() == TERRAIN_OCEAN) return 0;
      }break;
    case(STRUCT_BRIDGE):  {
      int ctr;
      flying = 1;
      for(ctr=0; ctr<12 && alt<=-100000; ctr+=2)  {
	Thing *tmpt = targ->Next(ctr)->Inside(0);
	while(tmpt != NULL)  {
	  if(tmpt->Type() == THING_STRUCT &&
		((Structure*)tmpt)->StructType() == STRUCT_BRIDGE)  {
	    alt = ((Structure*)tmpt)->altitude;
//	    printf("Set relative bridge alt to %d.\r\n", alt);
	    }
	  tmpt = tmpt->Inside(0);
	  }
	}
      if(alt <= -100000 && targ->Terrain() !=TERRAIN_LOWWATER
		&& targ->Terrain() !=TERRAIN_WATER
		&& targ->Terrain() != TERRAIN_OCEAN)  {
	Thing *tmpt = targ;
	while(tmpt->Inside(0) != NULL)  tmpt = tmpt->Inside(0);
	if(tmpt->Type() == THING_CELL || tmpt->Type() == THING_STRUCT)  {
	  alt = tmpt->Height();
	  break;
	  }
	return 0;
	}
      if(alt <= -100000) return 0;
      }break;
    }
  if(alt <= -100000) alt = targ->Height();
  else malt = alt-targ->Height();
  if(malt < 0) return 0;

//  printf("Attempting to claim for struct!\r\n");
  if(!(targ->Claim(this, alt, height, 0, malt)))  return 0;
//  printf("Attempting to enter for struct!\r\n");
  if(!(targ->Enter(this, alt, height, 0, malt)))  {
    targ->UnClaim(this);
    return 0;
    }
//  printf("Success!\r\n");
  targ->UnClaim(this);
  location[0] = targ;
  Changed[thingnum] = 1;
  if(struct_type == STRUCT_BRIDGE)  {
    altitude = alt;
//    printf("Placing Struct at altitude %d\r\n", altitude);
    }
  InitNeighbors();
  return 1;
  }