- Timestamp:
- 08/15/11 02:25:22 (13 years ago)
- Location:
- ps/trunk/binaries/data/mods/public/simulation
- Files:
-
- 4 edited
-
components/Player.js (modified) (6 diffs)
-
components/PlayerManager.js (modified) (1 diff)
-
helpers/Commands.js (modified) (1 diff)
-
helpers/Player.js (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/simulation/components/Player.js
r9865 r10008 23 23 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. 24 24 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) 26 26 this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class 27 27 this.phase = "village"; 28 28 this.startCam = undefined; 29 29 this.controlAllUnits = false; 30 this.isAI = false; 30 31 }; 31 32 … … 236 237 { 237 238 return this.startCam.position; 238 } 239 }; 239 240 240 241 Player.prototype.GetStartingCameraRot = function() 241 242 { 242 243 return this.startCam.rotation; 243 } 244 }; 244 245 245 246 Player.prototype.SetStartingCamera = function(pos, rot) 246 247 { 247 248 this.startCam = {"position": pos, "rotation": rot}; 248 } 249 }; 249 250 250 251 Player.prototype.HasStartingCamera = function() 251 252 { 252 253 return (this.startCam !== undefined); 253 } 254 }; 254 255 255 256 Player.prototype.SetControlAllUnits = function(c) 256 257 { 257 258 this.controlAllUnits = c; 258 } 259 }; 259 260 260 261 Player.prototype.CanControlAllUnits = function() 261 262 { 262 263 return this.controlAllUnits; 263 } 264 }; 265 266 Player.prototype.SetAI = function(flag) 267 { 268 this.isAI = flag; 269 }; 270 271 Player.prototype.IsAI = function() 272 { 273 return this.isAI; 274 }; 275 276 Player.prototype.SetAlly = function(id) 277 { 278 if (id >= 0 && id != this.playerID) 279 { 280 this.diplomacy[id] = 1; 281 } 282 }; 264 283 265 284 /** … … 268 287 Player.prototype.IsAlly = function(id) 269 288 { 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 292 Player.prototype.SetEnemy = function(id) 293 { 294 if (id >= 0 && id != this.playerID) 295 { 296 this.diplomacy[id] = -1; 297 } 298 }; 272 299 273 300 /** … … 276 303 Player.prototype.IsEnemy = function(id) 277 304 { 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 308 Player.prototype.SetNeutral = function(id) 309 { 310 if (id >= 0 && id != this.playerID) 311 { 312 this.diplomacy[id] = 0; 313 } 314 }; 280 315 281 316 /** … … 284 319 Player.prototype.IsNeutral = function(id) 285 320 { 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 }; 288 323 289 324 /** … … 346 381 cmpOwnership.SetOwner(0); 347 382 } 348 } 383 }; 349 384 350 385 Engine.RegisterComponentType(IID_Player, "Player", Player); -
ps/trunk/binaries/data/mods/public/simulation/components/PlayerManager.js
r8749 r10008 4 4 "<a:component type='system'/><empty/>"; 5 5 6 // Diplomatic stance constants7 PlayerManager.prototype.Diplomacy = {8 "ENEMY" : -1,9 "NEUTRAL" : 0,10 "ALLY" : 111 };12 13 6 PlayerManager.prototype.Init = function() 14 7 { -
ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js
r9970 r10008 144 144 cmpPosition.SetYRotation(cmd.angle); 145 145 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 } 163 160 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 } 185 184 186 185 var cmpCost = Engine.QueryInterface(ent, IID_Cost); -
ps/trunk/binaries/data/mods/public/simulation/helpers/Player.js
r9970 r10008 26 26 27 27 if (settings.PlayerData) 28 { // Get number of players including gaia28 { // Get number of players including gaia 29 29 numPlayers = settings.PlayerData.length + 1; 30 30 } … … 36 36 // Get player manager 37 37 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 38 39 var teams = []; 40 var diplomacy = []; 41 42 // Build team + diplomacy data 38 43 39 for (var i = 0; i < numPlayers; ++i) 44 40 { 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] : {}; 46 54 47 55 // Skip gaia … … 49 57 { 50 58 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) 58 87 { 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); 60 102 } 61 else62 {63 teams[team].push(i);64 }65 }66 }67 }68 69 for (var i = 0; i < numPlayers; ++i)70 {71 // Add player entity to engine72 var entID = Engine.AddEntity("special/player");73 74 // Retrieve entity75 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 gaia86 if (i > 0)87 {88 var pData = settings.PlayerData ? settings.PlayerData[i-1] : {};89 90 // Copy player data91 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 diplomacy110 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 diplomacy117 var teamDiplomacy = [];118 for (var p in diplomacy)119 {120 teamDiplomacy[p] = diplomacy[p];121 }122 // Set teammates to allies123 var myTeam = teams[team];124 for (var n in myTeam)125 {126 teamDiplomacy[myTeam[n]] = cmpPlayerMan.Diplomacy.ALLY; //Set ally127 }128 129 player.SetDiplomacy(teamDiplomacy);130 }131 else132 { //Set default133 player.SetDiplomacy(diplomacy);134 103 } 135 104 … … 137 106 if (startCam !== undefined) 138 107 { 139 player.SetStartingCamera(startCam.Position, startCam.Rotation);108 cmpPlayer.SetStartingCamera(startCam.Position, startCam.Rotation); 140 109 } 141 110 } 142 111 else 143 112 { // 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 } 148 121 } 149 122 … … 220 193 targetOwner = cmpOwnershipTarget.GetOwner(); 221 194 222 // Get our diplomacy array223 195 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 224 196 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(owner), IID_Player); … … 251 223 targetOwner = cmpOwnershipTarget.GetOwner(); 252 224 253 // Get our diplomacy array254 225 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 255 226 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(player), IID_Player); … … 273 244 targetOwner = cmpOwnershipTarget.GetOwner(); 274 245 275 // Get our diplomacy array276 246 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 277 247 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(player), IID_Player);
Note:
See TracChangeset
for help on using the changeset viewer.
