Changeset 521

Show
Ignore:
Timestamp:
04/26/08 06:50:21 (9 months ago)
Author:
LeoD
Message:

basics for attacking

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/run/data/shaders/terrain.pixel.glsl

    r520 r521  
     1#include shadowmap.glsl 
     2 
    13uniform sampler2D alpha; 
    24uniform sampler2D texture1; 
     
    57uniform sampler2D lightmap; 
    68uniform sampler2D shadow; 
    7  
    8 uniform vec3 lightPos; 
    99 
    1010varying vec4 lightSpacePos; 
     
    2323    c3 *= a.b * inverse;     
    2424     
    25     gl_FragColor = (c1 + c2 + c3) * (l * 2); 
    26  
    27     /*vec2 shadowMapCoord = 0.5f * lightSpacePos.xy / lightSpacePos.w + vec2(0.5f, 0.5f); 
    28     float shadowMapDistance = texture2D(shadow, shadowMapCoord).r; 
    29  
    30     #define FAR 300.0f 
    31     #define NEAR 50.0f 
    32      
    33     float lightDistance = (1.0f / NEAR - 1.0f / (lightSpacePos.z)) / (1.0f / NEAR - 1.0f / FAR); 
    34     lightDistance = lightSpacePos.z / lightSpacePos.w; 
    35      
    36     if(lightDistance < 0 || lightDistance > 1) // debugging 
    37     { 
    38         gl_FragColor = vec4(1, 0, 0, 0); 
    39         return; 
    40     } 
    41      
    42     float shadowValue = 1; 
    43      
    44     if(lightDistance + 0.2f >= shadowMapDistance && shadowMapDistance != 1.0f) // point is in shadow 
    45     { 
    46         shadowValue = 0.3; 
    47     } 
    48      
    49     if(shadowMapCoord.x >= 0 && shadowMapCoord.x <= 1 && shadowMapCoord.y >= 0 && shadowMapCoord.y <= 1) 
    50     { 
    51         //float x = shadowMapDistance - lightDistance; 
    52      
    53         gl_FragColor *= vec4(shadowValue, shadowValue, shadowValue, 0); 
    54         //gl_FragColor = vec4(lightDistance, lightDistance, lightDistance, 0); 
    55         //gl_FragColor = vec4(x, x, x, 0); 
    56         //gl_FragColor = vec4(shadowMapDistance, shadowMapDistance, shadowMapDistance, 0); 
    57     }*/ 
     25    gl_FragColor = (c1 + c2 + c3) * (l * 2); //* shadowMap(shadow, lightSpacePos); 
    5826} 
  • trunk/src/defend/Main.d

    r513 r521  
    191191        parser.parse(args[1 .. $]); 
    192192     
    193         gameConfig.recordDemo = !gameConfig.multiplayer.isServer; 
     193        gameConfig.recordDemo = gameConfig.multiplayer.isServer; 
    194194     
    195195        // Show help? 
  • trunk/src/defend/objects/Core.d

    r505 r521  
    651651 
    652652    Gateway gateway; 
    653     GameObjectManager manager
     653    GameObjectManager gameObjects
    654654 
    655655    vec3 _realPos; // The real position 
     
    696696        } 
    697697         
    698         manager.localRemove(id); 
     698        gameObjects.localRemove(id); 
    699699    } 
    700700     
     
    702702    void status(object_status_t s) 
    703703    { 
    704         assert(_status != Status.Dead); 
     704        //assert(_status != Status.Dead); 
    705705         
    706706        _status = s; 
     
    779779        { 
    780780            status = Status.Dead; 
    781             manager.objectDead(this); 
    782         } 
     781            //gameObjects.objectDead(this); 
     782            gameObjects.localRemove(id); 
     783        } 
     784    } 
     785     
     786    void hurt(int i) 
     787    { 
     788        life = life - min(life, i); 
    783789    } 
    784790 
     
    813819            if(element.effector is null) 
    814820            { 
    815                 element.whenApplied = manager.currentSimulationStep(); 
     821                element.whenApplied = gameObjects.currentSimulationStep(); 
    816822                element.effector = effector; 
    817823                 
     
    955961    void simulate() 
    956962    { 
    957         assert(!removed); 
     963        //assert(!removed); 
    958964 
    959965        foreach(element; effectors) 
    960966        { 
    961967            if(element.effector !is null && element.effector.lifetime != 0 && 
    962                manager.currentSimulationStep() - element.whenApplied == 0) 
     968               gameObjects.currentSimulationStep() - element.whenApplied == 0) 
    963969            { 
    964970                element.effector.detach(this); 
     
    971977    void afterSimulate() 
    972978    { 
    973         assert(!removed); 
     979        //assert(!removed); 
    974980    } 
    975981     
     
    15711577        object.mapPos = MapPos(x, y); 
    15721578        object.gateway = gateway; 
    1573         object.manager = this; 
     1579        object.gameObjects = this; 
    15741580        object.onCreate(); 
    15751581         
     
    15831589    } 
    15841590     
    1585     void objectDead(GameObject object) 
    1586     { 
     1591    deprecated void objectDead(GameObject object) 
     1592    { 
     1593        // wtf is that for lol 
    15871594        ObjectDead(object); 
    15881595    } 
  • trunk/src/defend/objects/types/Building.d

    r511 r521  
    1212import gen.scene.Graph; 
    1313import gen.scene.ModelNode; 
     14import gen.scene.ParticleSystem; 
    1415import gen.math.Rectangle; 
    1516import gen.math.Vector; 
     
    559560 
    560561        _sceneNode = new GameObjectModel(sceneGraph.root, buildingInfo.model, 
    561                                          playerColors[manager.players.get(owner).info.color]); 
    562         //_sceneNode.color = playerColors[manager.players.get(owner).info.color]; 
     562                                         playerColors[gameObjects.players.get(owner).info.color]); 
     563        //_sceneNode.color = playerColors[gameObjects.players.get(owner).info.color]; 
    563564         
    564565        realPos = terrain.getWorldPos(mapPos); 
     
    575576    { 
    576577        super.onRemove(); 
     578             
     579        //void spawn(vec3 point, uint number) 
     580             
     581        foreach(x, y; mapRectangle) 
     582            particles("smoke").spawn(terrain.getWorldPos(x, y) + vec3(0, 0.5, 1), 1); 
    577583             
    578584        markMap(true); 
     
    627633                    } 
    628634 
    629                     auto obj = cast(Unit)manager.localCreate(owner, 
     635                    auto obj = cast(Unit)gameObjects.localCreate(owner, 
    630636                                                             entry.unitType.objectType, 
    631637                                                             unitPos.x, 
  • trunk/src/defend/objects/types/Citizen.d

    r469 r521  
    3434            canBuild = [ "house" ]; 
    3535            properties[GameObject.Property.MaxLife] = 500; 
     36            properties[Unit.Property.Attack]        = 10; 
    3637            properties[Unit.Property.MovementSpeed] = 50; 
     38            properties[Unit.Property.AttackSpeed]   = 250; 
    3739        } 
    3840 
  • trunk/src/defend/objects/types/House.d

    r483 r521  
    2626            canDevelop = [ "sheep on drugs" ]; 
    2727            miniPic = "data/minipics/house.png"; 
     28            properties[GameObject.Property.MaxLife] = 2000; 
    2829        } 
    2930         
  • trunk/src/defend/objects/types/Sheep.d

    r515 r521  
    3333            developmentSteps = 18; 
    3434            properties[GameObject.Property.MaxLife] = 500; 
     35            properties[Unit.Property.Attack]        = 5; 
    3536            properties[Unit.Property.MovementSpeed] = 100; 
     37            properties[Unit.Property.AttackSpeed]   = 50; 
    3638        } 
    3739         
  • trunk/src/defend/objects/types/Unit.d

    r511 r521  
    167167    } 
    168168     
     169    override OrderError checkOrder(GameObject[] objects, OrderObjectRightClick* order) 
     170    { 
     171        auto target = gameObjects.getObject(order.target); 
     172     
     173        return OrderError.Okay; // tmp for testing 
     174        return target.owner != objects[0].owner ? 
     175               OrderError.Okay : OrderError.Error; 
     176    } 
     177     
    169178    override void onOrder(GameObject[] objects, OrderMapRightClick* order) 
    170179    { 
     180        // TODO: Group pathfinding 
    171181        iterateObjects(objects, (Unit object) 
    172182        { 
     
    182192        { 
    183193            object.finalDirection = direction; 
     194        }); 
     195    } 
     196     
     197    override void onOrder(GameObject[] objects, OrderObjectRightClick* order) 
     198    { 
     199        auto target = gameObjects.getObject(order.target); 
     200     
     201        iterateObjects(objects, (Unit object) 
     202        { 
     203            object.attack(target); 
    184204        }); 
    185205    } 
     
    239259                 
    240260                /* If the unit on this tile is moving too, 
    241                    we simply wait some ticks and go to the final goal then */ 
     261                   we simply wait some ticks and go to the final goal afterwards */ 
    242262                if(unit.moving && unit.movePause == 0 && 
    243263                   property(Unit.Property.MovementSpeed) <= 
    244264                   unit.property(Unit.Property.MovementSpeed)) 
    245265                { 
    246                     pause(3)
     266                    pause = 3
    247267                    path = []; 
    248268                     
     
    273293                        { 
    274294                            status = Status.Idle; 
    275                             moving = false; 
     295                            //moving = false; 
    276296                            direction = finalDirection; 
    277297                             
     
    302322                        trace("final goal reached"); 
    303323                 
    304                     moving = false; 
     324                    //moving = false; 
    305325                    status = Status.Idle; 
    306326                    direction = finalDirection; 
     
    403423    vec3 nextWayPoint; 
    404424    MapPos finalGoal; 
    405     bool moving = false; 
     425    //bool moving = false; 
     426    bool moving() { return status == Status.Moving; } 
    406427    vec3 direction; 
    407428    vec3 finalDirection; 
     
    409430    uint movePercent; // from 0 to 1000 
    410431    const MAX_MOVE_PERCENT = 1000; 
     432     
     433    // Attacking 
     434    GameObject target; // Attack target 
     435    uint attackCounter; // Countdown to the next attack 
    411436     
    412437    MapPos[] pathBuffer; 
     
    422447                    bool considerObjects = false, bool isFinalGoal = true) 
    423448    { 
    424         status = Status.Moving; 
    425          
    426449        if(isFinalGoal) 
    427450            finalGoal = p; 
     
    435458            path = map.getPath(mapPos, p, pathBuffer[1 .. $], considerObjects, this); 
    436459            path = pathBuffer[0 .. path.length == 0 ? 1 : path.length]; 
     460             
     461            assert(moving); 
    437462        } 
    438463        else 
     
    442467            if(path.length) 
    443468            { 
    444                 moving = true
    445                  
    446                 if(!checkCollision(path[0]) && moving
     469                status = Status.Moving
     470                 
     471                if(!checkCollision(path[0])
    447472                    moveToPoint(path[0]); 
    448473            } 
     
    451476        gateway.checkSync(__FILE__, __LINE__, id); 
    452477        gateway.checkSync(__FILE__, __LINE__, path.length); 
     478    } 
     479     
     480    // Attack another unit 
     481    void attack(GameObject object) 
     482    { 
     483        // TODO: !melee 
     484         
     485        target = object; 
     486        follow(target, &targetReached); 
     487         
     488        resetAttackCounter(); 
     489    } 
     490     
     491    void targetReached() 
     492    { 
     493        debug(unit) 
     494            trace("reached target"); 
     495     
     496        status = Status.Attacking; 
     497    } 
     498     
     499    void resetAttackCounter() 
     500    { 
     501        Stdout("setting counter to ")(cast(int)property(Property.AttackSpeed)).newline; 
     502     
     503        attackCounter = cast(int)property(Property.AttackSpeed); 
     504        assert(attackCounter > 0); 
    453505    } 
    454506     
     
    534586        Armour, 
    535587        Range, 
    536         MovementSpeed 
     588        MovementSpeed, 
     589        AttackSpeed 
    537590    } 
    538591 
     
    545598        dg("range", property(Property.Range)); 
    546599        dg("movement speed", property(Property.MovementSpeed)); 
     600        dg("attack speed", property(Property.AttackSpeed)); 
    547601    } 
    548602     
     
    553607        if(which is followObject) 
    554608            stopFollow(); 
     609             
     610        if(which is target) 
     611        { 
     612            target = null; 
     613            status = Status.Idle; 
     614        } 
    555615    } 
    556616     
     
    575635        realPos = terrain.getWorldPos(mapPos); 
    576636        finalGoal = mapPos; 
    577         moving = false; 
    578637         
    579638        pathPoolSlice = pathBuffer = pathPool.allocate(); 
    580639  
    581640        _sceneNode = new GameObjectModel(sceneGraph.root, unitInfo.model, 
    582                                          playerColors[manager.players.get(owner).info.color]); 
    583         //_sceneNode.color = playerColors[manager.players.get(owner).info.color]; 
     641                                         playerColors[gameObjects.players.get(owner).info.color]); 
     642        //_sceneNode.color = playerColors[gameObjects.players.get(owner).info.color]; 
    584643         
    585644        _realPos = terrain.getWorldPos(mapPos); 
     
    636695        super.simulate(); 
    637696         
    638         if(movePause > 0) 
    639         { 
    640             movePause--; 
    641              
    642             if(movePause == 0) 
    643             { 
    644                 if(!moving && mapPos != finalGoal) 
    645                     move(finalGoal, false, false, true); 
    646             } 
    647         } 
    648          
    649         if(moving) 
    650         { 
     697        switch(status) 
     698        { 
     699        case Status.Attacking: 
     700            if(!target) 
     701                status = Status.Idle; 
     702            else if(!--attackCounter) 
     703            { 
     704                target.hurt(cast(int)property(Property.Attack)); 
     705                 
     706                resetAttackCounter(); 
     707            } 
     708         
     709            break; 
     710         
     711        case Status.Moving: 
     712            // Continue moving after taking a break 
     713            if(movePause > 0) 
     714            { 
     715                movePause--; 
     716                 
     717                if(movePause == 0) 
     718                { 
     719                    if(!moving && mapPos != finalGoal) 
     720                        move(finalGoal, false, false, true); 
     721                } 
     722            } 
     723         
    651724            if(movePercent < MAX_MOVE_PERCENT) 
    652725                movePercent += property(Unit.Property.MovementSpeed); 
     
    655728                movePercent = MAX_MOVE_PERCENT; 
    656729             
     730            // Reached the next tile 
    657731            if(movePercent == MAX_MOVE_PERCENT) 
    658732            { 
     733                // Path finished 
    659734                if(path.length <= 1) 
    660735                { 
     
    662737                        trace("path finished"); 
    663738                     
    664                     moving = false; 
    665739                    status = Status.Idle; 
    666740                    path = []; 
     
    675749                    gateway.checkSync(__FILE__, __LINE__, id); 
    676750                } 
     751                 
     752                // Start walking to the next tile 
    677753                else if(!checkCollision(path[1]) && moving && path.length) 
    678754                { 
     
    682758            } 
    683759             
     760            // Calculate progress in percent of the current tile 
    684761            auto percent = movePercent / cast(float)MAX_MOVE_PERCENT; 
    685762            realPos = lastWayPoint * (1.0 - percent) + nextWayPoint * percent; 
    686763             
     764            // Path finished 
    687765            if(!path.length) 
    688766            { 
    689767                direction = finalDirection; 
    690                 moving = false; 
     768                //moving = false; 
     769                status = Status.Idle; 
    691770                moveFinished(); 
    692771            } 
     772             
     773            break; 
     774             
     775        default: 
     776            break; 
    693777        } 
    694778    } 
  • trunk/src/gen/rend/opengl/Renderer.d

    r520 r521  
    464464    override Texture createTexture(Image image) 
    465465    { 
     466        logger.info("creating {}*{} texture (from \"{}\")", image.width, image.height, image.file); 
     467     
    466468        return new OGLTexture(image); 
    467469    } 
     
    469471    override Texture createTexture(vec2i dimension, ImageFormat format) 
    470472    { 
     473        logger.info("creating {}*{} texture render target", dimension.x, dimension.y); 
     474     
    471475        return new OGLTexture(dimension, format); 
    472476    } 
     
    573577    override Shader createShader(char[] file) 
    574578    { 
     579        logger.info("creating shader from \"{}\"", file); 
     580     
    575581        return new OGLShader(file); 
    576582    } 
  • trunk/src/gen/rend/opengl/Shader.d

    r520 r521  
    22 
    33import tango.io.Stdout; 
     4import tango.io.File; 
    45import tango.io.FilePath; 
    56import tango.stdc.stringz; 
     7import tango.text.Util; 
    68 
    79import derelict.opengl.gl; 
     
    2527 
    2628    int[char[]] uniformHandles; 
     29 
     30    char[] preprocess(char[] basedir, char[] code) 
     31    { 
     32        char[] result; 
     33     
     34        foreach(line; lines(code)) 
     35        { 
     36            //Stdout(line).newline; 
     37         
     38            line = trim(line); 
     39         
     40            if(line.length && line[0] == '#') 
     41            { 
     42                if(auto pos = locate(line, ' ')) 
     43                { 
     44                    switch(line[1 .. pos]) 
     45                    { 
     46                    case "include": 
     47                        result ~= preprocess(basedir, cast(char[])(new File(basedir ~ line[pos + 1 .. $])).read); 
     48                        break; 
     49                         
     50                    default: 
     51                        result ~= line ~ "\n"; 
     52                    } 
     53                } 
     54            } 
     55            else 
     56                result ~= line ~ "\n"; 
     57        } 
     58         
     59        return result; 
     60    } 
    2761 
    2862    void checkError(int object, int type) 
     
    5589        auto codep = toStringz(code); 
    5690        int lengthp = code.length; 
     91         
     92        //Stdout("compiling....................").newline; 
    5793         
    5894        glShaderSourceARB(result, 1, &codep, &lengthp); 
     
    101137        context = glCreateProgramObjectARB(); 
    102138         
     139        char[] basedir; 
     140        foreach(part; split(file, "/")[0 .. $ - 1]) 
     141            basedir ~= part ~ "/"; 
     142         
     143        //Stdout(basedir).newline; 
     144         
    103145        char[] path = file ~ ".vertex.glsl"; 
    104146        if(FilePath(path).exists) withReadFile(path, (char[] code) 
    105147        { 
    106             vertexShaderObject = compile(code, GL_VERTEX_SHADER_ARB); 
     148            vertexShaderObject = compile(preprocess(basedir, code), GL_VERTEX_SHADER_ARB); 
    107149        }); 
    108150         
     
    110152        if(FilePath(path).exists) withReadFile(path, (char[] code) 
    111153        { 
    112             pixelShaderObject = compile(code, GL_FRAGMENT_SHADER_ARB); 
     154            pixelShaderObject = compile(preprocess(basedir, code), GL_FRAGMENT_SHADER_ARB); 
    113155        }); 
    114156