It would look like this:

Code:
//FIRST DETERMINE THE SITUATION
int situation=1;
if(closest_vertex<=verts_per_row)
{
   situation=2;
}

if(closest_vertex%verts_per_row==0)
{
   situation=3;
}

if(closest_vertex<=verts_per_row && closest_vertex%verts_per_row==0)
{
   situation=4;
}

//AFTER MANIPULATE THE VERTS DEPENDING ON THE SITUATION
if(situation==1)
{
   //manipulate four verts on current terrain as normal
}
else if(situation==2)
{
   //manipulate 2 verts on current terrain
   //manipulate 4 verts on terrain above
}
else if(situation==3)
{
   //manipulate 2 verts on current terrain
   //manipulate 4 verts on terrain to the right
}
else
{
   //manipulate one vert on current terrain
   //manipulate two verts on terrain above
   //manipulate two verts on terrain to the right
   //manipulate four verts on diagonal terrain
}







EDIT:
I just noticed there are 3 more cases I didn't account for!
-The inverse of case2
-The inverse of case3
-The inverse of case4
*These three inverted variations can be easily accounted for with an extra "if" inside the manipulation portion of the code, at the beginning of the three normal 2,3,4 situation "if"'s.

All of this will be much easier for you to program if you create your terrain pointers in an array, and use it's skills to reference their position in the array like this:
Code:
ENTITY* terrain_list[x][y];

void create_terrains()
{
   int x,y;
   for(x=0,x<terrains_count_horizontal;x++)
   {
      for(y=0,y<terrains_count_vertical;y++)
      {
         terrain_list[x][y]=ent_create("my_terrain.mdl",vector(x*terrain_width,y*terrain_depth,0),NULL);
         //to find the relative position later
         terrain_list[x][y].skill1=x;
         terrain_list[x][y].skill2=y;
      }
   }
}



NOTE:
The three extra "inverse cases" and array of terrain pointers will only be necessary if you have more than 4 terrains.

If you need further help on this I would need an example of how you calculate closest_vert and terrain_entity in your code to build the new code around that (and possibly modify how you calculate those if needed). It would also help to know if they are global, or if not, how you pass them in your function call. Also if you are using any defines or not, to make the new code more flexible.

Last edited by Carlos3DGS; 02/16/13 14:19. Reason: special cases and pointer reference

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1