This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 10008 for ps


Ignore:
Timestamp:
08/15/11 02:25:22 (13 years ago)
Author:
ben
Message:

Disables build restrictions and limits for AIs (until they can be fixed).
Simplifies player diplomacy/team setup.

Location:
ps/trunk/binaries/data/mods/public/simulation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/Player.js

    r9865 r10008  
    2323    this.team = -1; // team number of the player, players on the same team will always have ally diplomatic status - also this is useful for team emblems, scoring, etc.
    2424    this.state = "active"; // game state - one of "active", "defeated", "won"
    25     this.diplomacy = [];    // array of diplomatic stances for this player with respect to other players (including self)
     25    this.diplomacy = [];    // array of diplomatic stances for this player with respect to other players (including gaia and self)
    2626    this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class
    2727    this.phase = "village";
    2828    this.startCam = undefined;
    2929    this.controlAllUnits = false;
     30    this.isAI = false;
    3031};
    3132
     
    236237{
    237238    return this.startCam.position;
    238 }
     239};
    239240
    240241Player.prototype.GetStartingCameraRot = function()
    241242{
    242243    return this.startCam.rotation;
    243 }
     244};
    244245
    245246Player.prototype.SetStartingCamera = function(pos, rot)
    246247{
    247248    this.startCam = {"position": pos, "rotation": rot};
    248 }
     249};
    249250
    250251Player.prototype.HasStartingCamera = function()
    251252{
    252253    return (this.startCam !== undefined);
    253 }
     254};
    254255
    255256Player.prototype.SetControlAllUnits = function(c)
    256257{
    257258    this.controlAllUnits = c;
    258 }
     259};
    259260
    260261Player.prototype.CanControlAllUnits = function()
    261262{
    262263    return this.controlAllUnits;
    263 }
     264};
     265
     266Player.prototype.SetAI = function(flag)
     267{
     268    this.isAI = flag;
     269};
     270
     271Player.prototype.IsAI = function()
     272{
     273    return this.isAI;
     274};
     275
     276Player.prototype.SetAlly = function(id)
     277{
     278    if (id >= 0 && id != this.playerID)
     279    {
     280        this.diplomacy[id] = 1;
     281    }
     282};
    264283
    265284/**
     
    268287Player.prototype.IsAlly = function(id)
    269288{
    270     return (id >= 0 && (id == this.playerID || this.diplomacy[id] > 0));
    271 }
     289    return (id >= 0 && id < this.diplomacy.length && (id == this.playerID || this.diplomacy[id] > 0));
     290};
     291
     292Player.prototype.SetEnemy = function(id)
     293{
     294    if (id >= 0 && id != this.playerID)
     295    {
     296        this.diplomacy[id] = -1;
     297    }
     298};
    272299
    273300/**
     
    276303Player.prototype.IsEnemy = function(id)
    277304{
    278     return (id >= 0 && id != this.playerID && this.diplomacy[id] < 0);
    279 }
     305    return (id >= 0 && id < this.diplomacy.length && id != this.playerID && this.diplomacy[id] < 0);
     306};
     307
     308Player.prototype.SetNeutral = function(id)
     309{
     310    if (id >= 0 && id != this.playerID)
     311    {
     312        this.diplomacy[id] = 0;
     313    }
     314};
    280315
    281316/**
     
    284319Player.prototype.IsNeutral = function(id)
    285320{
    286     return (id >= 0 && id != this.playerID && this.diplomacy[id] == 0);
    287 }
     321    return (id >= 0 && id < this.diplomacy.length && id != this.playerID && this.diplomacy[id] == 0);
     322};
    288323
    289324/**
     
    346381        cmpOwnership.SetOwner(0);
    347382    }
    348 }
     383};
    349384
    350385Engine.RegisterComponentType(IID_Player, "Player", Player);
  • ps/trunk/binaries/data/mods/public/simulation/components/PlayerManager.js

    r8749 r10008  
    44    "<a:component type='system'/><empty/>";
    55
    6 // Diplomatic stance constants
    7 PlayerManager.prototype.Diplomacy = {
    8     "ENEMY" : -1,
    9     "NEUTRAL" : 0,
    10     "ALLY" : 1
    11 };
    12    
    136PlayerManager.prototype.Init = function()
    147{
  • ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js

    r9970 r10008  
    144144        cmpPosition.SetYRotation(cmd.angle);
    145145
    146         // Check whether it's obstructed by other entities or invalid terrain
    147         var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions);
    148         if (!cmpBuildRestrictions || !cmpBuildRestrictions.CheckPlacement(player))
    149         {
    150             var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    151             cmpGuiInterface.PushNotification({ "player": player, "message": "Building site was obstructed" });
    152 
    153             // Remove the foundation because the construction was aborted
    154             Engine.DestroyEntity(ent);
    155             break;
    156         }
    157        
    158         // Check build limits
    159         var cmpBuildLimits = QueryPlayerIDInterface(player, IID_BuildLimits);
    160         if (!cmpBuildLimits || !cmpBuildLimits.AllowedToBuild(cmpBuildRestrictions.GetCategory()))
    161         {
    162             // TODO: The UI should tell the user they can't build this (but we still need this check)
     146        // TODO: Build restrctions disabled for AI since it lacks a mechanism for checking most of them
     147        if (!cmpPlayer.IsAI())
     148        {
     149            // Check whether it's obstructed by other entities or invalid terrain
     150            var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions);
     151            if (!cmpBuildRestrictions || !cmpBuildRestrictions.CheckPlacement(player))
     152            {
     153                var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     154                cmpGuiInterface.PushNotification({ "player": player, "message": "Building site was obstructed" });
     155
     156                // Remove the foundation because the construction was aborted
     157                Engine.DestroyEntity(ent);
     158                break;
     159            }
    163160           
    164             // Remove the foundation because the construction was aborted
    165             Engine.DestroyEntity(ent);
    166             break;
    167         }
    168 
    169         /* TODO: the AI isn't smart enough to explore before building, so we'll
    170          * just disable the requirement that the location is visible. Should we
    171          * fix that, or let players build in fog too, or something?
    172 
    173         // Check whether it's in a visible region
    174         var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    175         var visible = (cmpRangeManager.GetLosVisibility(ent, player) == "visible");
    176         if (!visible)
    177         {
    178             // TODO: report error to player (the building site was not visible)
    179             print("Building site was not visible\n");
    180 
    181             Engine.DestroyEntity(ent);
    182             break;
    183         }
    184         */
     161            // Check build limits
     162            var cmpBuildLimits = QueryPlayerIDInterface(player, IID_BuildLimits);
     163            if (!cmpBuildLimits || !cmpBuildLimits.AllowedToBuild(cmpBuildRestrictions.GetCategory()))
     164            {
     165                // TODO: The UI should tell the user they can't build this (but we still need this check)
     166               
     167                // Remove the foundation because the construction was aborted
     168                Engine.DestroyEntity(ent);
     169                break;
     170            }
     171
     172            // Check whether it's in a visible region
     173            var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     174            var visible = (cmpRangeManager.GetLosVisibility(ent, player) == "visible");
     175            if (!visible)
     176            {
     177                // TODO: report error to player (the building site was not visible)
     178                print("Building site was not visible\n");
     179
     180                Engine.DestroyEntity(ent);
     181                break;
     182            }
     183        }
    185184       
    186185        var cmpCost = Engine.QueryInterface(ent, IID_Cost);
  • ps/trunk/binaries/data/mods/public/simulation/helpers/Player.js

    r9970 r10008  
    2626   
    2727    if (settings.PlayerData)
    28     {   //Get number of players including gaia
     28    {   // Get number of players including gaia
    2929        numPlayers = settings.PlayerData.length + 1;
    3030    }
     
    3636    // Get player manager
    3737    var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    38    
    39     var teams = [];
    40     var diplomacy = [];
    41    
    42     // Build team + diplomacy data
     38
    4339    for (var i = 0; i < numPlayers; ++i)
    4440    {
    45         diplomacy[i] = cmpPlayerMan.Diplomacy.ENEMY;
     41        // Add player entity to engine
     42        var entID = Engine.AddEntity("special/player");
     43       
     44        // Retrieve entity
     45        var cmpPlayer = Engine.QueryInterface(entID, IID_Player);
     46        if (!cmpPlayer)
     47        {
     48            throw("Player.js: Error creating player entity "+i);
     49        }
     50       
     51        cmpPlayer.SetPlayerID(i);
     52       
     53        var pDefs = playerDefaults ? playerDefaults[i] : {};
    4654       
    4755        // Skip gaia
     
    4957        {
    5058            var pData = settings.PlayerData ? settings.PlayerData[i-1] : {};
    51             var pDefs = playerDefaults ? playerDefaults[i] : {};
    52             var team = getSetting(pData, pDefs, "Team");
    53            
    54             // If team defined, add player to the team
    55             if (team !== undefined && team != -1)
    56             {
    57                 if (!teams[team])
     59           
     60            // Copy player data
     61            cmpPlayer.SetName(getSetting(pData, pDefs, "Name"));
     62            cmpPlayer.SetCiv(getSetting(pData, pDefs, "Civ"));
     63            cmpPlayer.SetAI(pData.AI && pData.AI != "");
     64           
     65            var colour = getSetting(pData, pDefs, "Colour");
     66            cmpPlayer.SetColour(colour.r, colour.g, colour.b);
     67           
     68            if (getSetting(pData, pDefs, "PopulationLimit") !== undefined)
     69            {
     70                cmpPlayer.SetMaxPopulation(getSetting(pData, pDefs, "PopulationLimit"));
     71            }
     72           
     73            if (getSetting(pData, pDefs, "Resources") !== undefined)
     74            {
     75                cmpPlayer.SetResourceCounts(getSetting(pData, pDefs, "Resources"));
     76            }
     77           
     78            // If diplomacy explicitly defined, use that; otherwise use teams
     79            if (getSetting(pData, pDefs, "Diplomacy") !== undefined)
     80            {
     81                cmpPlayer.SetDiplomacy(getSetting(pData, pDefs, "Diplomacy"));
     82            }
     83            else
     84            {
     85                var myTeam = getSetting(pData, pDefs, "Team");
     86                for (var j = 0; j < numPlayers; ++j)
    5887                {
    59                     teams[team] = [i];
     88                    // Check if player is on same team
     89                    if (j > 0)
     90                    {
     91                        var theirTeam = getSetting(settings.PlayerData[j-1], playerDefaults[j], "Team");
     92                        if (myTeam !== undefined && myTeam != -1
     93                            && theirTeam !== undefined && theirTeam != -1
     94                            && myTeam == theirTeam)
     95                        {
     96                            cmpPlayer.SetAlly(j);
     97                            continue;
     98                        }
     99                    }
     100                    // Gaia, different team, or no team defined
     101                    cmpPlayer.SetEnemy(j);
    60102                }
    61                 else
    62                 {
    63                     teams[team].push(i);
    64                 }
    65             }
    66         }
    67     }
    68 
    69     for (var i = 0; i < numPlayers; ++i)
    70     {
    71         // Add player entity to engine
    72         var entID = Engine.AddEntity("special/player");
    73        
    74         // Retrieve entity
    75         var player = Engine.QueryInterface(entID, IID_Player);
    76         if (!player)
    77         {
    78             throw("Player.js: Error creating player entity "+i);
    79         }
    80        
    81         player.SetPlayerID(i);
    82        
    83         var pDefs = playerDefaults ? playerDefaults[i] : {};
    84        
    85         // Skip gaia
    86         if (i > 0)
    87         {
    88             var pData = settings.PlayerData ? settings.PlayerData[i-1] : {};
    89            
    90             // Copy player data
    91             player.SetName(getSetting(pData, pDefs, "Name"));
    92             player.SetCiv(getSetting(pData, pDefs, "Civ"));
    93            
    94             var colour = getSetting(pData, pDefs, "Colour");
    95             player.SetColour(colour.r, colour.g, colour.b);
    96            
    97             if (getSetting(pData, pDefs, "PopulationLimit") !== undefined)
    98             {
    99                 player.SetMaxPopulation(getSetting(pData, pDefs, "PopulationLimit"));
    100             }
    101            
    102             if (getSetting(pData, pDefs, "Resources") !== undefined)
    103             {
    104                 player.SetResourceCounts(getSetting(pData, pDefs, "Resources"));
    105             }
    106            
    107             var team = getSetting(pData, pDefs, "Team");
    108            
    109             //If diplomacy array exists use that, otherwise use team data or default diplomacy
    110             if (getSetting(pData, pDefs, "Diplomacy") !== undefined)
    111             {
    112                 player.SetDiplomacy(getSetting(pData, pDefs, "Diplomacy"));
    113             }
    114             else if (team !== undefined && team != -1)
    115             {
    116                 //Team exists, copy default diplomacy
    117                 var teamDiplomacy = [];
    118                 for (var p in diplomacy)
    119                 {
    120                     teamDiplomacy[p] = diplomacy[p];
    121                 }
    122                 // Set teammates to allies
    123                 var myTeam = teams[team];
    124                 for (var n in myTeam)
    125                 {
    126                     teamDiplomacy[myTeam[n]] = cmpPlayerMan.Diplomacy.ALLY; //Set ally
    127                 }
    128                
    129                 player.SetDiplomacy(teamDiplomacy);
    130             }
    131             else
    132             {   //Set default
    133                 player.SetDiplomacy(diplomacy);
    134103            }
    135104           
     
    137106            if (startCam !== undefined)
    138107            {
    139                 player.SetStartingCamera(startCam.Position, startCam.Rotation);
     108                cmpPlayer.SetStartingCamera(startCam.Position, startCam.Rotation);
    140109            }
    141110        }
    142111        else
    143112        {   // Copy gaia data from defaults
    144             player.SetName(pDefs.Name);
    145             player.SetCiv(pDefs.Civ);
    146             player.SetColour(pDefs.Colour.r, pDefs.Colour.g, pDefs.Colour.b);
    147             player.SetDiplomacy(diplomacy);
     113            cmpPlayer.SetName(pDefs.Name);
     114            cmpPlayer.SetCiv(pDefs.Civ);
     115            cmpPlayer.SetColour(pDefs.Colour.r, pDefs.Colour.g, pDefs.Colour.b);
     116           
     117            for (var j = 0; j < numPlayers; ++j)
     118            {   // Gaia is everyone's enemy
     119                cmpPlayer.SetEnemy(j);
     120            }
    148121        }
    149122       
     
    220193        targetOwner = cmpOwnershipTarget.GetOwner();
    221194
    222     // Get our diplomacy array
    223195    var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    224196    var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(owner), IID_Player);
     
    251223        targetOwner = cmpOwnershipTarget.GetOwner();
    252224
    253     // Get our diplomacy array
    254225    var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    255226    var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(player), IID_Player);
     
    273244        targetOwner = cmpOwnershipTarget.GetOwner();
    274245
    275     // Get our diplomacy array
    276246    var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    277247    var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(player), IID_Player);
Note: See TracChangeset for help on using the changeset viewer.