UserFunction; asteroidAdd - HWRM/KarosGraveyard Wiki

asteroidAdd(<tPosition>, <sLayout>, <rDistribution>, <iNumResources>, <fA>, <fB>, <fC>, <fRotY>, <fRotZ>)

Description

Adds Homeworld 1 style asteroid/pebble fields to your map. Uses nearly the same syntax as Homeworld 1.
Note: you must call the function from within the DetermChunk() function.
Warning: there's a statistical likelihood that some asteroids might overlap, resulting in resource collectors becoming stuck and not being able to move.

Example

asteroidAdd({0, 0, 0,}, "Box", thisOne, 500, 1000, 1000, 1000, 0, 0)

Arguments

<tPosition>: a table consisting of the resource patch's X, Y, and Z coordinates.
<sLayout>: can either be "Cylinder", "Sphere", or "Box".
<rDistribution>: a reference to the distribution table.
<iNumResources>: the total number of asteroids and/or pebbles.
<fA>, <fB>, <fC>: differ depending on whether you choose the "Cylinder", "Sphere", or "Box" layouts. If "Cylinder", then <fA> and <fB> are the inner and outer radii, and <fC> is the cylinder's height. If "Sphere", then <fA> and <fB> are the inner and outer radii, and <fC> is not calculated (a value must still be present, though). If "Box", then <fA> is the length, <fB> is the width, and <fC> is the height.
<fRotY>, <fRotZ>: the rotation angles around the Y and Z axes, respectively.

Notes

Just like in Homeworld 1, this function uses resource distributions. In the following block of code you must set the relative amounts of each type of asteroid or pebble within a distribution table. For, example, for every three "Pebble_0"s you have one "Asteroid_3". Or, for every two "Asteroid_2"s you have five "Pebble_1"s. You can store any number of distribution tables in your ".level" file by copying it once, and then pasting and renaming it each time.
Note: distribution tables must also be declared within the DetermChunk() function, and must be declared before any functions that refer to them.

For example:

local thisOne =
{
Pebble_0 = 3,
Pebble_1 = 3,
Pebble_2 = 2,
Asteroid_1 = 3,
Asteroid_2 = 2,
Asteroid_3 = 1,
Asteroid_4 = 0,
Asteroid_5 = 0,
}

And:

local thatOne =
{
Pebble_0 = 0,
Pebble_1 = 1,
Pebble_2 = 3,
Asteroid_1 = 1,
Asteroid_2 = 0,
Asteroid_3 = 2,
Asteroid_4 = 1,
Asteroid_5 = 3,
}

The first distribution table is different than the second one. Specify the one you want by passing the name of the table as the <rDistribution> argument.

Definition

updated 2006-01-27

This portion must exist outside both the DetermChunk() and NonDetermChunk() functions, and must be left unchanged.

function asteroidAdd(tPosition, sLayout, rDistribution, iNumResources, fA, fB, fC, fRotY, fRotZ)
    -- function created by Mikali
    local Relative = 0
    local Amount = 0
    local Modulos = 0
    for k, iCount in rDistribution do
        Relative = Relative + iCount
    end
    for k, iCount in rDistribution do
        if (Relative > 0) then
            Amount = floor(iCount * iNumResources / Relative)
            Modulos = Modulos + mod(iCount * iNumResources, Relative)
        end
        for i = 1, Amount do
            local r, u, v, l, w, h, cooX, cooY, cooZ = random(fA), random(180), random(360), random(-fA, fA), random(-fB, fB), random(-fC, fC), 0, 0, 0
            if (sLayout == "Cylinder") then
                cooX = w / 2
                cooY = r * sin(v)
                cooZ = r * cos(v)
            elseif (sLayout == "Sphere") then
                cooX = r * cos(u)
                cooY = r * sin(v) * sin(u)
                cooZ = r * cos(v) * sin(u)
            elseif (sLayout == "Box") then
                cooX = l
                cooY = w
                cooZ = h
                fRotY = 0
            end
            local yCooX = cooX * cos(fRotY) + cooZ * sin(fRotY)
            local yCooY = cooY * 1
            local yCooZ = cooX * -1 * sin(fRotY) + cooZ * cos(fRotY)
            local zCooX = yCooX * cos(fRotZ) - yCooY * sin(fRotZ)
            local zCooY = yCooX * sin(fRotZ) + yCooY * cos(fRotZ)
            local zCooZ = yCooZ * 1
            local tCoordinates = {tPosition[1] + zCooX, tPosition[2] + zCooY, tPosition[3] + zCooZ,}
            if ((k == "Asteroid_1") or (k == "Asteroid_2") or (k == "Asteroid_3") or (k == "Asteroid_4") or (k == "Asteroid_5")) then
                addAsteroid(k, tCoordinates, 100, 0, 0, 0, 0)
            elseif ((k == "Pebble_0") or (k == "Pebble_1") or (k == "Pebble_2")) then
                addPebble(k, tCoordinates, 0, 0, 0)
            end
        end
    end
    if (Modulos > 0) then
        asteroidAdd(tPosition, sLayout, rDistribution, Modulos, fA, fB, fC, fRotY, fRotZ)
    end
end

Related Pages

User-Created Functions

How to Make Resource Patches in Simple Shapes

HW2 Mapping: Basic Shapes

Comments

Updated the function.

--Mikali (2006-01-27 18:16:34)

Page Status

Updated Formatting? Initial
Updated for HWRM? Initial