mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 09:06:49 +00:00
allow the use of allied dropsites using tech, fixes #3791
This was SVN commit r17875.
This commit is contained in:
BIN
Binary file not shown.
@@ -224,8 +224,9 @@ g_SelectionPanels.Command = {
|
||||
},
|
||||
"setGraphics": function(data)
|
||||
{
|
||||
data.icon.sprite = "stretched:session/icons/" + data.item.icon;
|
||||
data.button.enabled = controlsPlayer(data.unitEntState.player);
|
||||
let grayscale = data.button.enabled ? "" : "grayscale:";
|
||||
data.icon.sprite = "stretched:" + grayscale + "session/icons/" + data.item.icon;
|
||||
},
|
||||
"setPosition": function(data)
|
||||
{
|
||||
@@ -280,8 +281,9 @@ g_SelectionPanels.AllyCommand = {
|
||||
},
|
||||
"setGraphics": function(data)
|
||||
{
|
||||
data.icon.sprite = "stretched:session/icons/" + data.item.icon;
|
||||
data.button.enabled = data.item.count > 0;
|
||||
data.button.enabled = data.item.count != undefined && data.item.count > 0;
|
||||
let grayscale = data.button.enabled ? "" : "grayscale:";
|
||||
data.icon.sprite = "stretched:" + grayscale + "session/icons/" + data.item.icon;
|
||||
},
|
||||
"setPosition": function(data)
|
||||
{
|
||||
|
||||
@@ -270,9 +270,15 @@ var unitActions =
|
||||
},
|
||||
"getActionInfo": function(entState, targetState)
|
||||
{
|
||||
if (!targetState.resourceDropsite)
|
||||
if (!targetState.resourceDropsite || !targetState.resourceDropsite.sharable)
|
||||
return false;
|
||||
if (!playerCheck(entState, targetState, ["Player"]))
|
||||
var playerState = GetSimState().players[entState.player];
|
||||
if (playerState.hasSharedDropsites && targetState.resourceDropsite.shared)
|
||||
{
|
||||
if (!playerCheck(entState, targetState, ["Player", "MutualAlly"]))
|
||||
return false;
|
||||
}
|
||||
else if (!playerCheck(entState, targetState, ["Player"]))
|
||||
return false;
|
||||
if (!entState.resourceCarrying || !entState.resourceCarrying.length)
|
||||
return false;
|
||||
@@ -872,7 +878,7 @@ var g_EntityCommands =
|
||||
},
|
||||
},
|
||||
// Trading
|
||||
"select-trading-goods": {
|
||||
"select-trading-goods": {
|
||||
"getInfo": function(entState)
|
||||
{
|
||||
if (!hasClass(entState, "Market"))
|
||||
@@ -887,6 +893,34 @@ var g_EntityCommands =
|
||||
toggleTrade();
|
||||
},
|
||||
},
|
||||
// Dropsite sharing
|
||||
"share-dropsite": {
|
||||
"getInfo": function(entState)
|
||||
{
|
||||
if (!entState.resourceDropsite || !entState.resourceDropsite.sharable)
|
||||
return false;
|
||||
let playerState = GetSimState().players[entState.player];
|
||||
if (!playerState.isMutualAlly.some((e, i) => e && i != entState.player))
|
||||
return false;
|
||||
if (entState.resourceDropsite.shared)
|
||||
return {
|
||||
"tooltip": translate("Press to prevent allies from using this dropsite"),
|
||||
"icon": "lock_unlocked.png"
|
||||
};
|
||||
return {
|
||||
"tooltip": translate("Press to allow allies to use this dropsite"),
|
||||
"icon": "lock_locked.png"
|
||||
};
|
||||
},
|
||||
"execute": function(entState)
|
||||
{
|
||||
Engine.PostNetworkCommand({
|
||||
"type": "set-dropsite-sharing",
|
||||
"entities": [entState.id],
|
||||
"shared": !entState.resourceDropsite.shared
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
var g_AllyEntityCommands =
|
||||
@@ -923,6 +957,29 @@ var g_AllyEntityCommands =
|
||||
unloadAllByOwner();
|
||||
},
|
||||
},
|
||||
// Dropsite sharing
|
||||
"share-dropsite": {
|
||||
"getInfo": function(entState)
|
||||
{
|
||||
if (!GetSimState().players[Engine.GetPlayerID()].hasSharedDropsites)
|
||||
return false;
|
||||
if (!entState.resourceDropsite || !entState.resourceDropsite.sharable)
|
||||
return false;
|
||||
if (entState.resourceDropsite.shared)
|
||||
return {
|
||||
"tooltip": translate("You are allowed to use this dropsite"),
|
||||
"icon": "lock_unlocked.png"
|
||||
};
|
||||
return {
|
||||
"tooltip": translate("The use of this dropsite is prohibited"),
|
||||
"icon": "lock_locked.png"
|
||||
};
|
||||
},
|
||||
"execute": function(entState)
|
||||
{
|
||||
// This command button is always disabled
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
function playerCheck(entState, targetState, validPlayers)
|
||||
|
||||
@@ -264,6 +264,14 @@ m.BaseManager.prototype.assignResourceToDropsite = function (gameState, dropsite
|
||||
});
|
||||
} */
|
||||
}
|
||||
|
||||
// Allows all allies to use this dropsite except if base anchor to be sure to keep
|
||||
// a minimum of resources for this base
|
||||
Engine.PostCommand(PlayerID, {
|
||||
"type": "set-dropsite-sharing",
|
||||
"entities": [dropsiteId],
|
||||
"shared": dropsiteId !== this.anchorId
|
||||
});
|
||||
};
|
||||
|
||||
// completely remove the dropsite resources from our list.
|
||||
|
||||
@@ -106,6 +106,7 @@ GuiInterface.prototype.GetSimulationState = function(player)
|
||||
"teamsLocked": cmpPlayer.GetLockTeams(),
|
||||
"cheatsEnabled": cmpPlayer.GetCheatsEnabled(),
|
||||
"disabledTemplates": cmpPlayer.GetDisabledTemplates(),
|
||||
"hasSharedDropsites": cmpPlayer.HasSharedDropsites(),
|
||||
"phase": phase,
|
||||
"isAlly": allies,
|
||||
"isMutualAlly": mutualAllies,
|
||||
@@ -516,7 +517,9 @@ GuiInterface.prototype.GetExtendedEntityState = function(player, ent)
|
||||
let cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite);
|
||||
if (cmpResourceDropsite)
|
||||
ret.resourceDropsite = {
|
||||
"types": cmpResourceDropsite.GetTypes()
|
||||
"types": cmpResourceDropsite.GetTypes(),
|
||||
"sharable": cmpResourceDropsite.IsSharable(),
|
||||
"shared": cmpResourceDropsite.IsShared()
|
||||
};
|
||||
|
||||
let cmpPromotion = Engine.QueryInterface(ent, IID_Promotion);
|
||||
|
||||
@@ -3,6 +3,9 @@ function Player() {}
|
||||
Player.prototype.Schema =
|
||||
"<element name='SharedLosTech' a:help='Allies will share los when this technology is researched. Leave empty to never share LOS.'>" +
|
||||
"<text/>" +
|
||||
"</element>" +
|
||||
"<element name='SharedDropsitesTech' a:help='Allies will share dropsites when this technology is researched. Leave empty to never share dropsites.'>" +
|
||||
"<text/>" +
|
||||
"</element>";
|
||||
|
||||
Player.prototype.Init = function()
|
||||
@@ -31,6 +34,7 @@ Player.prototype.Init = function()
|
||||
this.teamsLocked = false;
|
||||
this.state = "active"; // game state - one of "active", "defeated", "won"
|
||||
this.diplomacy = []; // array of diplomatic stances for this player with respect to other players (including gaia and self)
|
||||
this.sharedDropsites = false;
|
||||
this.formations = [];
|
||||
this.startCam = undefined;
|
||||
this.controlAllUnits = false;
|
||||
@@ -507,6 +511,11 @@ Player.prototype.HasStartingCamera = function()
|
||||
return (this.startCam !== undefined);
|
||||
};
|
||||
|
||||
Player.prototype.HasSharedDropsites = function()
|
||||
{
|
||||
return this.sharedDropsites;
|
||||
};
|
||||
|
||||
Player.prototype.SetControlAllUnits = function(c)
|
||||
{
|
||||
this.controlAllUnits = c;
|
||||
@@ -680,6 +689,8 @@ Player.prototype.OnResearchFinished = function(msg)
|
||||
{
|
||||
if (msg.tech == this.template.SharedLosTech)
|
||||
this.UpdateSharedLos();
|
||||
else if (msg.tech == this.template.SharedDropsitesTech)
|
||||
this.sharedDropsites = true;
|
||||
};
|
||||
|
||||
Player.prototype.OnDiplomacyChanged = function()
|
||||
|
||||
@@ -12,9 +12,16 @@ ResourceDropsite.prototype.Schema =
|
||||
"</choice>" +
|
||||
"</zeroOrMore>" +
|
||||
"</list>" +
|
||||
"</element>" +
|
||||
"<element name='Sharable' a:help='Allows allies to use this entity.'>" +
|
||||
"<data type='boolean'/>" +
|
||||
"</element>";
|
||||
|
||||
ResourceDropsite.prototype.Serialize = null;
|
||||
ResourceDropsite.prototype.Init = function()
|
||||
{
|
||||
this.sharable = this.template.Sharable == "true";
|
||||
this.shared = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the list of resource types accepted by this dropsite.
|
||||
@@ -33,4 +40,20 @@ ResourceDropsite.prototype.AcceptsType = function(type)
|
||||
return this.GetTypes().indexOf(type) != -1;
|
||||
};
|
||||
|
||||
ResourceDropsite.prototype.IsSharable = function()
|
||||
{
|
||||
return this.sharable;
|
||||
};
|
||||
|
||||
ResourceDropsite.prototype.IsShared = function()
|
||||
{
|
||||
return this.shared;
|
||||
};
|
||||
|
||||
ResourceDropsite.prototype.SetSharing = function(value)
|
||||
{
|
||||
if (this.sharable)
|
||||
this.shared = value;
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_ResourceDropsite, "ResourceDropsite", ResourceDropsite);
|
||||
|
||||
@@ -4061,8 +4061,17 @@ UnitAI.prototype.FindNearestDropsite = function(genericType)
|
||||
if (!cmpOwnership || cmpOwnership.GetOwner() == -1)
|
||||
return undefined;
|
||||
|
||||
// Find dropsites owned by this unit's player
|
||||
var players = [cmpOwnership.GetOwner()];
|
||||
// Find dropsites owned by this unit's player or allied ones if allowed
|
||||
var owner = cmpOwnership.GetOwner();
|
||||
var players = [owner];
|
||||
var cmpPlayer = QueryOwnerInterface(this.entity);
|
||||
if (cmpPlayer && cmpPlayer.HasSharedDropsites())
|
||||
{
|
||||
let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
for (let i = 1; i < cmpPlayerManager.GetNumPlayers(); ++i)
|
||||
if (i != owner && cmpPlayer.IsMutualAlly(i))
|
||||
players.push(i);
|
||||
}
|
||||
|
||||
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
||||
var nearby = cmpRangeManager.ExecuteQuery(this.entity, 0, -1, players, IID_ResourceDropsite);
|
||||
@@ -4072,7 +4081,13 @@ UnitAI.prototype.FindNearestDropsite = function(genericType)
|
||||
if (excludeLand)
|
||||
nearby = nearby.filter(e => Engine.QueryInterface(e, IID_Identity).HasClass("Naval"));
|
||||
|
||||
return nearby.find(ent => Engine.QueryInterface(ent, IID_ResourceDropsite).AcceptsType(genericType));
|
||||
return nearby.find(ent => {
|
||||
let cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite);
|
||||
if (!cmpResourceDropsite.AcceptsType(genericType))
|
||||
return false;
|
||||
let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
|
||||
return cmpOwnership.GetOwner() == owner || cmpResourceDropsite.IsShared();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -5753,9 +5768,13 @@ UnitAI.prototype.CanReturnResource = function(target, checkCarriedResource)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify that the dropsite is owned by this entity's player
|
||||
// Verify that the dropsite is owned by this entity's player (or an a mutual allied if allowed)
|
||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
||||
return cmpOwnership && IsOwnedByPlayer(cmpOwnership.GetOwner(), target);
|
||||
var cmpPlayer = QueryOwnerInterface(this.entity);
|
||||
if (cmpOwnership && IsOwnedByPlayer(cmpOwnership.GetOwner(), target))
|
||||
return true;
|
||||
return cmpPlayer && cmpPlayer.HasSharedDropsites() && cmpResourceDropsite.IsShared() &&
|
||||
cmpOwnership && IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target);
|
||||
};
|
||||
|
||||
UnitAI.prototype.CanTrade = function(target)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"genericName": "Diaspora",
|
||||
"description": "The extension of trade leads to the permanent establishment of storekeepers and their families in foreign countries, allowing them to exploit these countries wealth.",
|
||||
"cost": { "food": 200, "wood": 200, "stone": 100, "metal": 100 },
|
||||
"requirements": { "class": "Trader", "number": 3 },
|
||||
"requirementsTooltip": "Requires 3 Traders",
|
||||
"supersedes": "unlock_shared_los",
|
||||
"icon": "diaspora.png",
|
||||
"researchTime": 40,
|
||||
"tooltip": "Player can use his allies dropsites.",
|
||||
"modifications": [{ "value": "Player/sharedDropsites", "replace": true }],
|
||||
"soundComplete": "interface/alarm/alarm_upgradearmory.xml"
|
||||
}
|
||||
@@ -685,6 +685,16 @@ var g_Commands = {
|
||||
// Currently nothing. Triggers can read it anyway, and send this
|
||||
// message to any component you like.
|
||||
},
|
||||
|
||||
"set-dropsite-sharing": function(player, cmd, data)
|
||||
{
|
||||
for (let ent of data.entities)
|
||||
{
|
||||
let cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite);
|
||||
if (cmpResourceDropsite && cmpResourceDropsite.IsSharable())
|
||||
cmpResourceDropsite.SetSharing(cmd.shared);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
</Identity>
|
||||
<Player>
|
||||
<SharedLosTech>unlock_shared_los</SharedLosTech>
|
||||
<SharedDropsitesTech>unlock_shared_dropsites</SharedDropsitesTech>
|
||||
</Player>
|
||||
<StatisticsTracker/>
|
||||
<TechnologyManager/>
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
<Entity>
|
||||
<Player>
|
||||
<SharedLosTech/>
|
||||
<SharedDropsitesTech/>
|
||||
</Player>
|
||||
</Entity>
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
</RallyPointRenderer>
|
||||
<ResourceDropsite>
|
||||
<Types>food wood stone metal</Types>
|
||||
<Sharable>true</Sharable>
|
||||
</ResourceDropsite>
|
||||
<VisualActor>
|
||||
<Actor>structures/britons/crannog.xml</Actor>
|
||||
|
||||
+5
-7
@@ -68,10 +68,7 @@
|
||||
<Identity>
|
||||
<GenericName>Civic Center</GenericName>
|
||||
<Tooltip>Build to acquire large tracts of territory. Train citizens. Garrison: 20.</Tooltip>
|
||||
<Classes datatype="tokens">
|
||||
Defensive
|
||||
CivCentre
|
||||
</Classes>
|
||||
<Classes datatype="tokens">Defensive CivCentre</Classes>
|
||||
<VisibleClasses datatype="tokens">CivilCentre</VisibleClasses>
|
||||
<Icon>structures/civic_centre.png</Icon>
|
||||
</Identity>
|
||||
@@ -97,6 +94,7 @@
|
||||
</ProductionQueue>
|
||||
<ResourceDropsite>
|
||||
<Types>food wood stone metal</Types>
|
||||
<Sharable>true</Sharable>
|
||||
</ResourceDropsite>
|
||||
<Sound>
|
||||
<SoundGroups>
|
||||
@@ -104,9 +102,9 @@
|
||||
<constructed>interface/complete/building/complete_civ_center.xml</constructed>
|
||||
<attack>attack/weapon/arrowfly.xml</attack>
|
||||
<death>attack/destruction/building_collapse_large.xml</death>
|
||||
<alert0>interface/alarm/alarm_alert_0.xml</alert0>
|
||||
<alert1>interface/alarm/alarm_alert_1.xml</alert1>
|
||||
<alert2>interface/alarm/alarm_alert_2.xml</alert2>
|
||||
<alert0>interface/alarm/alarm_alert_0.xml</alert0>
|
||||
<alert1>interface/alarm/alarm_alert_1.xml</alert1>
|
||||
<alert2>interface/alarm/alarm_alert_2.xml</alert2>
|
||||
</SoundGroups>
|
||||
</Sound>
|
||||
<TerritoryInfluence>
|
||||
|
||||
+1
@@ -49,6 +49,7 @@
|
||||
<RallyPoint disable=""/>
|
||||
<ResourceDropsite>
|
||||
<Types>food</Types>
|
||||
<Sharable>true</Sharable>
|
||||
</ResourceDropsite>
|
||||
<Sound>
|
||||
<SoundGroups>
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<BatchTimeModifier>0.7</BatchTimeModifier>
|
||||
<Technologies datatype="tokens">
|
||||
unlock_shared_los
|
||||
unlock_shared_dropsites
|
||||
trade_convoys_speed
|
||||
trade_convoys_armor
|
||||
trade_gain_01
|
||||
|
||||
+2
-6
@@ -23,12 +23,7 @@
|
||||
<Identity>
|
||||
<GenericName>Storehouse</GenericName>
|
||||
<Tooltip>Dropsite for wood, stone, and metal resources. Research gathering improvements for these resources.</Tooltip>
|
||||
<Classes datatype="tokens">
|
||||
DropsiteWood
|
||||
DropsiteMetal
|
||||
DropsiteStone
|
||||
-ConquestCritical
|
||||
</Classes>
|
||||
<Classes datatype="tokens">DropsiteWood DropsiteMetal DropsiteStone -ConquestCritical</Classes>
|
||||
<VisibleClasses datatype="tokens">Village Storehouse</VisibleClasses>
|
||||
<Icon>structures/storehouse.png</Icon>
|
||||
</Identity>
|
||||
@@ -62,6 +57,7 @@
|
||||
<RallyPoint disable=""/>
|
||||
<ResourceDropsite>
|
||||
<Types>wood stone metal</Types>
|
||||
<Sharable>true</Sharable>
|
||||
</ResourceDropsite>
|
||||
<Sound>
|
||||
<SoundGroups>
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
</RallyPointRenderer>
|
||||
<ResourceDropsite>
|
||||
<Types>food wood stone metal</Types>
|
||||
<Sharable>true</Sharable>
|
||||
</ResourceDropsite>
|
||||
<Sound>
|
||||
<SoundGroups>
|
||||
@@ -71,7 +72,7 @@
|
||||
armor_ship_hullsheathing
|
||||
</Technologies>
|
||||
</ProductionQueue>
|
||||
<Vision>
|
||||
<Vision>
|
||||
<Range>40</Range>
|
||||
</Vision>
|
||||
<VisualActor>
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
</Position>
|
||||
<ResourceDropsite>
|
||||
<Types>food wood stone metal</Types>
|
||||
<Sharable>false</Sharable>
|
||||
</ResourceDropsite>
|
||||
<Selectable>
|
||||
<Overlay>
|
||||
|
||||
Reference in New Issue
Block a user