private bool testCol(int X_indx, int Y_indx, float angle)
        {
            // Are we going to run into anyone?
            int neighbors;
            int x;
            int angletemp;

            MathFunctions.location[] nextspot = new MathFunctions.location[7];
            //Out next spot along the same path.

            // First test to see if our projected locale will be out of bounds.
            for (x = 0; x <= 12; x += 6)
            {
                angletemp = (int)angle + x;
                if (angletemp > 359)
                {
                    angletemp = 0 + x;
                }

                nextspot[x / 6].x = Math.Sign(OuterSpace.moveX[angletemp]);
                nextspot[x / 6].y = Math.Sign(OuterSpace.moveY[angletemp]);

                angletemp = (int)angle - x;
                if (angletemp < 0)
                {
                    angletemp = 359 - x;
                }

                nextspot[x / 6 + 3].x = Math.Sign(OuterSpace.moveX[angletemp]);
                nextspot[x / 6 + 3].y = Math.Sign(OuterSpace.moveY[angletemp]);
            }

            for (x = 0; x <= 5; x++)
            {
                nextspot[x] = MathFunctions.outOfBounds((float)X_indx + nextspot[x].x, (float)Y_indx + nextspot[x].y, 0F, 0F, (float)OuterSpace.thisPlanet.PlanetMaps.BigMapX, (float)OuterSpace.thisPlanet.PlanetMaps.BigMapY, (short)angle, false);
            }

            // Test all neighboring cells in our path for other lifeforms.
            neighbors = 0;
            for (x = 0; x <= 5; x++)
            {
                neighbors = neighbors + OuterSpace.thisPlanet.lifemap[(int)nextspot[x].x, (int)nextspot[x].y].type;
                neighbors = neighbors + OuterSpace.thisPlanet.lifemap[(int)nextspot[x].x, Y_indx].type;
                neighbors = neighbors + OuterSpace.thisPlanet.lifemap[X_indx, (int)nextspot[x].y].type;
            }

            if (neighbors > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        //3-11-06 ...
        public void scanNewterrian(int startX, int startY, bool reloadVB)
        {
            // Tesselate the 30,30 viewable section of terrian 3 times. Repopulate zmap based on the updated position.
            // reload the vertex buffer with the updated terrian.
            int lifeC;
            int i = 0;
            int iy;
            int ix;
            int zx; // The current x index of the zmap arrary.
            int zy; // The current y index of the zmap arrary.
            int arrayX; // The current x index of the map arrary.
            int arrayY; // The current y index of the map arrary.
            int bigmX; // Store the dimensions of our map locally.
            int bigmY;
            MathFunctions.location testMapOut = new MathFunctions.location();

            bigmX = (int)OuterSpace.thisPlanet.PlanetMaps.BigMapX;
            bigmY = (int)OuterSpace.thisPlanet.PlanetMaps.BigMapY;

            for (ix = 0; ix < 100; ix++) //Reset the zlifemap.
            {
                zlifemap[ix].xptr = -99;
                zlifemap[ix].yptr = -99;
            }

            // Load the zmap with the inital nXn square of viewable terrian. Talking into account the edges.
            zy = 0;
            lifeC = 0;
            for (iy = startY + (zmapsdim / 2 - 1); iy >= startY - (zmapsdim / 2); iy--)
            {
                arrayY = iy;
                zx = 0;

                for (ix = startX + (zmapsdim / 2 - 1); ix >= startX - (zmapsdim / 2); ix--)
                {
                    arrayX = ix;

                    testMapOut = MathFunctions.outOfBounds(arrayX, arrayY, 0, 0, OuterSpace.thisPlanet.PlanetMaps.BigMapX, OuterSpace.thisPlanet.PlanetMaps.BigMapY, 0, true);
                    arrayY = (int)testMapOut.y;
                    arrayX = (int)testMapOut.x;

                    // Assign the spot to the zmap.
                    zmap[zx, zy] = map[bigmX - arrayX,
                        bigmY - arrayY];

                    // Assign our minerals based on the planets mineralmap
                    if (OuterSpace.thisPlanet.mineralmap[bigmX - arrayX, bigmY - arrayY])
                    {
                        zobjectmap[zx, zy].mineral = OuterSpace.thisPlanet.mineralmap[bigmX - arrayX, bigmY - arrayY];
                    }
                    // Assign our lifeforms based on the planets lifeformmap
                    if (OuterSpace.thisPlanet.lifemap[bigmX - arrayX,
                        bigmY - arrayY].type > 0)
                    {
                        // Point to the life form in the big map.
                        zlifemap[lifeC].xptr = (short)(bigmX - arrayX);
                        zlifemap[lifeC].yptr = (short)(bigmY - arrayY);

                        OuterSpace.msgbox.pushmsgs("We are here, getting life");

                        //Have we ever calculated this lifeform//s screen position?
                        if (OuterSpace.thisPlanet.lifemap[bigmX - arrayX,
                            bigmY - arrayY].sX == 0 ||
                            OuterSpace.thisPlanet.lifemap[bigmX - arrayX,
                            bigmY - arrayY].sY == 0)
                        {
                            OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sX = bigmX / 2 - ix;
                            OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sY = bigmY / 2 - iy;
                        }

                        if (OutOnX)  //if we've crossed the x meridian we have to make some special exceptions.
                        {
                            //if it's a plant, lets re-calculate the screen position.
                            if (OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].type / 10 < 10)
                            {
                                OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sX = bigmX / 2 - ix;
                                OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sY = bigmY / 2 - iy;
                            }    //if it's a life form, we need to update it//s x-position.
                            else
                            {
                                OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sX = bigmX / 2 - ix -
                                    OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].deltaX;
                            }
                        }

                        lifeC++;
                        //Set the Sx and Sy variables.
                        OuterSpace.debugfile.Output(Convert.ToString(bigmX - arrayX) + "," + Convert.ToString(bigmY - arrayY) + "," +
                            Convert.ToString(bigmX / 2 - ix) + "," + Convert.ToString(bigmY / 2 - iy) + "," +
                            Convert.ToString(OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sX) + "," +
                            Convert.ToString(OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sY) + "," +
                            Convert.ToString((OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].deltaX)));
                    }

                    // Assign our ship placement on the zobject map if we are near it in this batch of terrian.
                    if ((ix - OuterSpace.thisPlanet.PlanetMaps.BigMapX / 2.0F) + 0.5F == OuterSpace.playership.X &&
                        (iy - OuterSpace.thisPlanet.PlanetMaps.BigMapY / 2.0F) + 0.5F == OuterSpace.playership.Y)
                    {
                        zobjectmap[zx, zy].ship = true;
                    }
                    else
                    {
                        zobjectmap[zx, zy].ship = false;
                    }

                    //Assign the vertex X,Y positions so we can draw them on the screen even if they are
                    //outside of our logical map dimensions.
                    zmap[zx, zy].X = OuterSpace.thisPlanet.PlanetMaps.BigMapX / 2 - ix;
                    zmap[zx, zy].Y = OuterSpace.thisPlanet.PlanetMaps.BigMapY / 2 - iy;
                    zx++;

                }

                zy++;
            }

            for (iy = 0; iy <= (zmapsdim - 2); iy++)
            {
                for (ix = 0; ix <= (zmapsdim - 2); ix++)
                {
                    // Use the points organized in a deresoluter dimensional array to make a list of quads.
                    triangles[i].A = zmap[ix, iy + 1];
                    triangles[i].B = zmap[ix, iy];
                    triangles[i].C = zmap[ix + 1, iy + 1];
                    triangles[i + 1].A = zmap[ix, iy];
                    triangles[i + 1].B = zmap[ix + 1, iy];
                    triangles[i + 1].C = zmap[ix + 1, iy + 1];
                    i += 2;
                }
            }

            maxtriangles = i;

            for (i = 0; i <= maxtriangles; i++)
            {
                triangles[i].A.normal = new Vector3(0.0F, 0.0F, -1.0F);
                triangles[i].B.normal = new Vector3(0.0F, 0.0F, -1.0F);
                triangles[i].C.normal = new Vector3(0.0F, 0.0F, -1.0F);
            }

            if (reloadVB) OuterSpace.thisPlanet.ReSetVB();

            OutOnX = false;
        }
        private void wander(ref short X_indx, ref short Y_indx)
        {
            //Are we going to run into anyone?

            if (rnd.NextDouble() * 55 > 52)
            {
                onBehavior = 2;
            }
            if (onBehavior == 2)
            {
                angle = (short)(angle + (rnd.NextDouble() * 6 - 3));

                if (angle > 359)
                {
                    angle = 1;
                }
                else if (angle < 1)
                {
                    angle = 359;
                }

                if (rnd.NextDouble() * 55 > 35)
                {
                    onBehavior = 1;
                }
            }

            if (testCol(X_indx, Y_indx, angle))
            {
                //If there is another life form in our dirrection
                //change our angle and try to go around on the next cycle.
                angle = (short)(angle + ((type % 2) - 1) * 3);
                //even numbered types of life will turn left, odd will turn right.
                if (angle > 359)
                {
                    angle = 1;
                }
                if (angle < 1)
                {
                    angle = 359;
                }
                OuterSpace.msgbox.pushmsgs("Animal Collision!");
                return;
            }

            // Adjust the displacement from index.
            deltaX = deltaX + OuterSpace.moveX[angle] * speed;
            deltaY = deltaY + OuterSpace.moveY[angle] * speed;

            // Adjust our screen position.
            sX = sX + OuterSpace.moveX[angle] * speed;
            sY = sY + OuterSpace.moveY[angle] * speed;

            // If we've moved more then 1, adjust our pointer, which was passed by refrence.
            // and adjust our lifemap array, shuffle memory locations around.
            if (Math.Abs(deltaX) > 1 | Math.Abs(deltaY) > 1)
            {
                //Make sure we are not going out of bounds.
                //when we adjust our array position.
                MathFunctions.location ifOut = new MathFunctions.location();

                ifOut.x = (int)X_indx + deltaX / 1;
                ifOut.y = (int)Y_indx + deltaY / 1;

                ifOut = MathFunctions.outOfBounds(ifOut.x, ifOut.y, 0, 0, OuterSpace.thisPlanet.PlanetMaps.BigMapX, OuterSpace.thisPlanet.PlanetMaps.BigMapY, angle, false);
                OuterSpace.thisPlanet.lifemap[(int)ifOut.x, (int)ifOut.y] = null;
                OuterSpace.thisPlanet.lifemap[(int)ifOut.x, (int)ifOut.y] = new lifeforms();
                //Create a new one
                OuterSpace.thisPlanet.lifemap[(int)ifOut.x, (int)ifOut.y] = OuterSpace.thisPlanet.lifemap[X_indx, Y_indx];
                //Assign the old
                OuterSpace.thisPlanet.lifemap[X_indx, Y_indx]      = new lifeforms();
                OuterSpace.thisPlanet.lifemap[X_indx, Y_indx].type = 0;
                OuterSpace.thisPlanet.lifemap[X_indx, Y_indx].sX   = 0;
                OuterSpace.thisPlanet.lifemap[X_indx, Y_indx].sY   = 0;
                OuterSpace.thisPlanet.lifemap[(int)ifOut.x, (int)ifOut.y].angle = ifOut.angle;

                //Update the pointers and the deltas with their new values.
                X_indx = (short)ifOut.x;
                deltaX = deltaX - (int)deltaX / 1;
                Y_indx = (short)ifOut.y;
                deltaY = deltaY - (int)deltaY / 1;
            }
        }
Exemple #4
0
        private void wander(ref short X_indx, ref short Y_indx)
        {
            //Are we going to run into anyone?

            if (rnd.NextDouble() * 55 > 52)
            {
                onBehavior = 2;
            }
            if (onBehavior == 2)
            {
                angle = (short)(angle + (rnd.NextDouble() * 6 - 3));

                if (angle > 359)
                    angle = 1;
                else if (angle < 1)
                    angle = 359;

                if (rnd.NextDouble() * 55 > 35)
                {
                    onBehavior = 1;
                }
            }

            if (testCol(X_indx, Y_indx, angle))
            {
                //If there is another life form in our dirrection
                //change our angle and try to go around on the next cycle.
                angle = (short)(angle + ((type % 2) - 1) * 3);
                //even numbered types of life will turn left, odd will turn right.
                if (angle > 359)
                    angle = 1;
                if (angle < 1)
                    angle = 359;
                OuterSpace.msgbox.pushmsgs("Animal Collision!");
                return;
            }

            // Adjust the displacement from index.
            deltaX = deltaX + OuterSpace.moveX[angle] * speed;
            deltaY = deltaY + OuterSpace.moveY[angle] * speed;

            // Adjust our screen position.
            sX = sX + OuterSpace.moveX[angle] * speed;
            sY = sY + OuterSpace.moveY[angle] * speed;

            // If we've moved more then 1, adjust our pointer, which was passed by refrence.
            // and adjust our lifemap array, shuffle memory locations around.
            if (Math.Abs(deltaX) > 1 | Math.Abs(deltaY) > 1)
            {
                //Make sure we are not going out of bounds.
                //when we adjust our array position.
                MathFunctions.location ifOut = new MathFunctions.location();

                ifOut.x = (int)X_indx + deltaX / 1;
                ifOut.y = (int)Y_indx + deltaY / 1;

                ifOut = MathFunctions.outOfBounds(ifOut.x, ifOut.y, 0, 0, OuterSpace.thisPlanet.PlanetMaps.BigMapX, OuterSpace.thisPlanet.PlanetMaps.BigMapY, angle, false);
                OuterSpace.thisPlanet.lifemap[(int)ifOut.x, (int)ifOut.y] = null;
                OuterSpace.thisPlanet.lifemap[(int)ifOut.x, (int)ifOut.y] = new lifeforms();
                //Create a new one
                OuterSpace.thisPlanet.lifemap[(int)ifOut.x, (int)ifOut.y] = OuterSpace.thisPlanet.lifemap[X_indx, Y_indx];
                //Assign the old
                OuterSpace.thisPlanet.lifemap[X_indx, Y_indx] = new lifeforms();
                OuterSpace.thisPlanet.lifemap[X_indx, Y_indx].type = 0;
                OuterSpace.thisPlanet.lifemap[X_indx, Y_indx].sX = 0;
                OuterSpace.thisPlanet.lifemap[X_indx, Y_indx].sY = 0;
                OuterSpace.thisPlanet.lifemap[(int)ifOut.x, (int)ifOut.y].angle = ifOut.angle;

                //Update the pointers and the deltas with their new values.
                X_indx = (short)ifOut.x;
                deltaX = deltaX - (int)deltaX / 1;
                Y_indx = (short)ifOut.y;
                deltaY = deltaY - (int)deltaY / 1;
            }
        }
Exemple #5
0
        private bool testCol(int X_indx, int Y_indx, float angle)
        {
            // Are we going to run into anyone?
            int neighbors;
            int x;
            int angletemp;
            MathFunctions.location[] nextspot = new MathFunctions.location[7];
            //Out next spot along the same path.

            // First test to see if our projected locale will be out of bounds.
            for (x = 0; x <= 12; x += 6)
            {
                angletemp = (int)angle + x;
                if (angletemp > 359) angletemp = 0 + x;

                nextspot[x / 6].x = Math.Sign(OuterSpace.moveX[angletemp]);
                nextspot[x / 6].y = Math.Sign(OuterSpace.moveY[angletemp]);

                angletemp = (int)angle - x;
                if (angletemp < 0) angletemp = 359 - x;

                nextspot[x / 6 + 3].x = Math.Sign(OuterSpace.moveX[angletemp]);
                nextspot[x / 6 + 3].y = Math.Sign(OuterSpace.moveY[angletemp]);
            }

            for (x = 0; x <= 5; x++)
            {
                nextspot[x] = MathFunctions.outOfBounds((float)X_indx + nextspot[x].x, (float)Y_indx + nextspot[x].y, 0F, 0F, (float)OuterSpace.thisPlanet.PlanetMaps.BigMapX, (float)OuterSpace.thisPlanet.PlanetMaps.BigMapY, (short)angle, false);
            }

            // Test all neighboring cells in our path for other lifeforms.
            neighbors = 0;
            for (x = 0; x <= 5; x++)
            {
                neighbors = neighbors + OuterSpace.thisPlanet.lifemap[(int)nextspot[x].x, (int)nextspot[x].y].type;
                neighbors = neighbors + OuterSpace.thisPlanet.lifemap[(int)nextspot[x].x, Y_indx].type;
                neighbors = neighbors + OuterSpace.thisPlanet.lifemap[X_indx, (int)nextspot[x].y].type;
            }

            if (neighbors > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //3-11-06 ...
        public void scanNewterrian(int startX, int startY, bool reloadVB)
        {
            // Tesselate the 30,30 viewable section of terrian 3 times. Repopulate zmap based on the updated position.
            // , reload the vertex buffer with the updated terrian.
            int lifeC;
            int i = 0;
            int iy;
            int ix;
            int zx;     // The current x index of the zmap arrary.
            int zy;     // The current y index of the zmap arrary.
            int arrayX; // The current x index of the map arrary.
            int arrayY; // The current y index of the map arrary.
            int bigmX;  // Store the dimensions of our map locally.
            int bigmY;

            MathFunctions.location testMapOut = new MathFunctions.location();

            bigmX = (int)OuterSpace.thisPlanet.PlanetMaps.BigMapX;
            bigmY = (int)OuterSpace.thisPlanet.PlanetMaps.BigMapY;

            for (ix = 0; ix < 100; ix++) //Reset the zlifemap.
            {
                zlifemap[ix].xptr = -99;
                zlifemap[ix].yptr = -99;
            }

            // Load the zmap with the inital nXn square of viewable terrian. Talking into account the edges.
            zy    = 0;
            lifeC = 0;
            for (iy = startY + (zmapsdim / 2 - 1); iy > startY - (zmapsdim / 2); iy--)
            {
                arrayY = iy;
                zx     = 0;

                for (ix = startX + (zmapsdim / 2 - 1); ix > startX - (zmapsdim / 2); ix--)
                {
                    arrayX = ix;

                    testMapOut = MathFunctions.outOfBounds(arrayX, arrayY, 0, 0, OuterSpace.thisPlanet.PlanetMaps.BigMapX, OuterSpace.thisPlanet.PlanetMaps.BigMapY, 0, true);
                    arrayY     = (int)testMapOut.y;
                    arrayX     = (int)testMapOut.x;

                    // Assign the spot to the zmap.
                    zmap[zx, zy] = map[bigmX - arrayX,
                                       bigmY - arrayY];

                    // Assign our minerals based on the planets mineralmap
                    zobjectmap[zx, zy].mineral = OuterSpace.thisPlanet.mineralmap[bigmX - arrayX, bigmY - arrayY];

                    // Assign our lifeforms based on the planets lifeformmap
                    if (OuterSpace.thisPlanet.lifemap[bigmX - arrayX,
                                                      bigmY - arrayY].type > 0)
                    {
                        // Point to the life form in the big map.
                        zlifemap[lifeC].xptr = (short)(bigmX - arrayX);
                        zlifemap[lifeC].yptr = (short)(bigmY - arrayY);

                        OuterSpace.msgbox.pushmsgs("We are here, getting life");

                        //Have we ever calculated this lifeform//s screen position?
                        if (OuterSpace.thisPlanet.lifemap[bigmX - arrayX,
                                                          bigmY - arrayY].sX == 0 ||
                            OuterSpace.thisPlanet.lifemap[bigmX - arrayX,
                                                          bigmY - arrayY].sY == 0)
                        {
                            OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sX = bigmX / 2 - ix;
                            OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sY = bigmY / 2 - iy;
                        }

                        if (OutOnX)  //if we've crossed the x meridian we have to make some special exceptions.
                        {
                            //if it's a plant, lets re-calculate the screen position.
                            if (OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].type / 10 < 10)
                            {
                                OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sX = bigmX / 2 - ix;
                                OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sY = bigmY / 2 - iy;
                            }    //if it's a life form, we need to update it//s x-position.
                            else
                            {
                                OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sX = bigmX / 2 - ix -
                                                                                                   OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].deltaX;
                            }
                        }

                        lifeC++;
                        //Set the Sx and Sy variables.
                        OuterSpace.debugfile.Output(Convert.ToString(bigmX - arrayX) + "," + Convert.ToString(bigmY - arrayY) + "," +
                                                    Convert.ToString(bigmX / 2 - ix) + "," + Convert.ToString(bigmY / 2 - iy) + "," +
                                                    Convert.ToString(OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sX) + "," +
                                                    Convert.ToString(OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].sY) + "," +
                                                    Convert.ToString((OuterSpace.thisPlanet.lifemap[bigmX - arrayX, bigmY - arrayY].deltaX)));
                    }

                    // Assign our ship placement on the zobject map if we are near it in this batch of terrian.
                    if ((ix - OuterSpace.thisPlanet.PlanetMaps.BigMapX / 2) + 0.5 == OuterSpace.playership.X &&
                        (iy - OuterSpace.thisPlanet.PlanetMaps.BigMapY / 2) + 0.5 == OuterSpace.playership.Y)
                    {
                        zobjectmap[zx, zy].ship = true;
                    }
                    else
                    {
                        zobjectmap[zx, zy].ship = false;
                    }

                    //Assign the vertex X,Y positions so we can draw them on the screen even if they are
                    //outside of our logical map dimensions.
                    zmap[zx, zy].X = OuterSpace.thisPlanet.PlanetMaps.BigMapX / 2 - ix;
                    zmap[zx, zy].Y = OuterSpace.thisPlanet.PlanetMaps.BigMapY / 2 - iy;
                    zx++;
                }

                zy++;
            }

            for (iy = 0; iy < (zmapsdim - 2); iy++)
            {
                for (ix = 0; ix < (zmapsdim - 2); ix++)
                {
                    // Use the points organized in a deresoluter dimensional array to make a list of quads.
                    triangles[i].A     = zmap[ix, iy + 1];
                    triangles[i].B     = zmap[ix, iy];
                    triangles[i].C     = zmap[ix + 1, iy + 1];
                    triangles[i + 1].A = zmap[ix, iy];
                    triangles[i + 1].B = zmap[ix + 1, iy];
                    triangles[i + 1].C = zmap[ix + 1, iy + 1];
                    i += 2;
                }
            }

            maxtriangles = i;

            for (i = 0; i < maxtriangles; i++)
            {
                triangles[i].A.normal = new Vector3(0.0F, 0.0F, -1.0F);
                triangles[i].B.normal = new Vector3(0.0F, 0.0F, -1.0F);
                triangles[i].C.normal = new Vector3(0.0F, 0.0F, -1.0F);
            }

            if (reloadVB)
            {
                OuterSpace.thisPlanet.ReSetVB();
            }

            OutOnX = false;
        }