forked from 0ad/0ad
petra: cleanup of chat messages based on patch by bb, refs #4326
This was SVN commit r19109.
This commit is contained in:
parent
92ea4af49e
commit
3c56638e8b
@ -14,3 +14,11 @@ function randomNormal2D()
|
|||||||
s = Math.sqrt(-2 * Math.log(s) / s);
|
s = Math.sqrt(-2 * Math.log(s) / s);
|
||||||
return [a * s, b * s];
|
return [a * s, b * s];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a random element of the source array
|
||||||
|
*/
|
||||||
|
function pickRandom(source)
|
||||||
|
{
|
||||||
|
return source.length ? source[Math.floor(source.length * Math.random())] : undefined;
|
||||||
|
}
|
||||||
|
@ -54,13 +54,6 @@ m.AssocArraytoArray = function(assocArray)
|
|||||||
return endArray;
|
return endArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Picks a random element from an array */
|
|
||||||
m.PickRandom = function(list)
|
|
||||||
{
|
|
||||||
return list.length ? list[Math.floor(Math.random()*list.length)] : undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/** Utility functions for conversions of maps of different sizes */
|
/** Utility functions for conversions of maps of different sizes */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +51,7 @@ m.AttackManager.prototype.checkEvents = function(gameState, events)
|
|||||||
for (let evt of events.PlayerDefeated)
|
for (let evt of events.PlayerDefeated)
|
||||||
this.defeated[evt.playerId] = true;
|
this.defeated[evt.playerId] = true;
|
||||||
|
|
||||||
let answer = false;
|
let answer = "decline";
|
||||||
let other;
|
let other;
|
||||||
let targetPlayer;
|
let targetPlayer;
|
||||||
for (let evt of events.AttackRequest)
|
for (let evt of events.AttackRequest)
|
||||||
@ -94,8 +94,10 @@ m.AttackManager.prototype.checkEvents = function(gameState, events)
|
|||||||
attack.requested = true;
|
attack.requested = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
answer = true;
|
answer = "join";
|
||||||
}
|
}
|
||||||
|
else if (other !== undefined)
|
||||||
|
answer = "other";
|
||||||
break; // take only the first attack request into account
|
break; // take only the first attack request into account
|
||||||
}
|
}
|
||||||
if (targetPlayer !== undefined)
|
if (targetPlayer !== undefined)
|
||||||
|
@ -1,7 +1,57 @@
|
|||||||
var PETRA = function(m)
|
var PETRA = function(m)
|
||||||
{
|
{
|
||||||
|
|
||||||
m.chatNewDiplomacyMessages = {
|
m.launchAttackMessages = {
|
||||||
|
"hugeAttack": [
|
||||||
|
markForTranslation("I am starting a massive military campaign against %(_player_)s, come and join me."),
|
||||||
|
markForTranslation("I have set up an huge army to crush %(_player_)s. Join me and you will have your share of the loot.")
|
||||||
|
],
|
||||||
|
"other": [
|
||||||
|
markForTranslation("I am launching an attack against %(_player_)s."),
|
||||||
|
markForTranslation("I have just sent an army against %(_player_)s.")
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
m.answerRequestAttackMessages = {
|
||||||
|
"join": [
|
||||||
|
markForTranslation("Let me regroup my army and I am with you against %(_player_)s."),
|
||||||
|
markForTranslation("I am doing the final preparation and I will attack %(_player_)s.")
|
||||||
|
],
|
||||||
|
"decline": [
|
||||||
|
markForTranslation("Sorry, I do not have enough soldiers currently, but my next attack will target %(_player_)s.")
|
||||||
|
],
|
||||||
|
"other": [
|
||||||
|
markForTranslation("I cannot help you against %(_player_)s for the time being, as I have another attack foreseen against %(_player_2)s.")
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
m.sentTributeMessages = [
|
||||||
|
markForTranslation("Here is a gift for %(_player_)s, make a good use of it."),
|
||||||
|
markForTranslation("I see you are in a bad situation %(_player_)s, I hope this will help."),
|
||||||
|
markForTranslation("I can help you this time %(_player_)s, but try to assemble more resources in the future.")
|
||||||
|
];
|
||||||
|
|
||||||
|
m.requestTributeMessages = [
|
||||||
|
markForTranslation("I am in need of %(resource)s, can you help? I will make it up to you."),
|
||||||
|
markForTranslation("I would participate more efficiently in our common war effort if you could provide me some %(resource)s."),
|
||||||
|
markForTranslation("If you have some %(resource)s excess, that would help me strengthen my army.")
|
||||||
|
];
|
||||||
|
|
||||||
|
m.newTradeRouteMessages = [
|
||||||
|
markForTranslation("I have set up a new route with %(_player_)s. Trading will be profitable for all of us."),
|
||||||
|
markForTranslation("A new trade route is set up with %(_player_)s. Take your share of the profits.")
|
||||||
|
];
|
||||||
|
|
||||||
|
m.newPhaseMessages = {
|
||||||
|
"started": [
|
||||||
|
markForTranslation("I am advancing to the %(phase)s.")
|
||||||
|
],
|
||||||
|
"completed": [
|
||||||
|
markForTranslation("I have reached the %(phase)s.")
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
m.newDiplomacyMessages = {
|
||||||
"ally": [
|
"ally": [
|
||||||
markForTranslation("%(_player_)s and I are now allies.")
|
markForTranslation("%(_player_)s and I are now allies.")
|
||||||
],
|
],
|
||||||
@ -15,18 +65,9 @@ m.chatNewDiplomacyMessages = {
|
|||||||
|
|
||||||
m.chatLaunchAttack = function(gameState, player, type)
|
m.chatLaunchAttack = function(gameState, player, type)
|
||||||
{
|
{
|
||||||
let message;
|
|
||||||
let proba = Math.random();
|
|
||||||
if (type === "HugeAttack" && proba > 0.25 && proba < 0.75)
|
|
||||||
message = markForTranslation("I am starting a massive military campaign against %(_player_)s, come and join me.");
|
|
||||||
else if (proba < 0.5)
|
|
||||||
message = markForTranslation("I am launching an attack against %(_player_)s.");
|
|
||||||
else
|
|
||||||
message = markForTranslation("I have just sent an army against %(_player_)s.");
|
|
||||||
|
|
||||||
Engine.PostCommand(PlayerID, {
|
Engine.PostCommand(PlayerID, {
|
||||||
"type": "aichat",
|
"type": "aichat",
|
||||||
"message": "/allies "+ message,
|
"message": "/allies " + pickRandom(this.launchAttackMessages[type === "HugeAttack" ? type : "other"]),
|
||||||
"translateMessage": true,
|
"translateMessage": true,
|
||||||
"translateParameters": ["_player_"],
|
"translateParameters": ["_player_"],
|
||||||
"parameters": { "_player_": player }
|
"parameters": { "_player_": player }
|
||||||
@ -35,52 +76,20 @@ m.chatLaunchAttack = function(gameState, player, type)
|
|||||||
|
|
||||||
m.chatAnswerRequestAttack = function(gameState, player, answer, other)
|
m.chatAnswerRequestAttack = function(gameState, player, answer, other)
|
||||||
{
|
{
|
||||||
let message;
|
Engine.PostCommand(PlayerID, {
|
||||||
if (answer)
|
|
||||||
{
|
|
||||||
let proba = Math.random();
|
|
||||||
if (proba < 0.5)
|
|
||||||
message = markForTranslation("Let me regroup my army and I am with you against %(_player_)s.");
|
|
||||||
else
|
|
||||||
message = markForTranslation("I am doing the final preparation and I will attack %(_player_)s.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (other !== undefined)
|
|
||||||
message = markForTranslation("I cannot help you against %(_player_)s for the time being, as I have another attack foreseen against %(_player_2)s.");
|
|
||||||
else
|
|
||||||
message = markForTranslation("Sorry, I do not have enough soldiers currently, but my next attack will target %(_player_)s.");
|
|
||||||
}
|
|
||||||
|
|
||||||
let chat = {
|
|
||||||
"type": "aichat",
|
"type": "aichat",
|
||||||
"message": "/allies " + message,
|
"message": "/allies " + pickRandom(this.answerRequestAttackMessages[answer]),
|
||||||
"translateMessage": true,
|
"translateMessage": true,
|
||||||
"translateParameters": ["_player_"],
|
"translateParameters": answer != "other" ? ["_player_"] : ["_player_", "_player_2"],
|
||||||
"parameters": { "_player_": player }
|
"parameters": answer != "other" ? { "_player_": player } : { "_player_": player, "_player2_": other }
|
||||||
};
|
});
|
||||||
if (other !== undefined)
|
|
||||||
{
|
|
||||||
chat.translateParameters.push("_player_2");
|
|
||||||
chat.parameters._player_2 = other;
|
|
||||||
}
|
|
||||||
Engine.PostCommand(PlayerID, chat);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
m.chatSentTribute = function(gameState, player)
|
m.chatSentTribute = function(gameState, player)
|
||||||
{
|
{
|
||||||
let message;
|
|
||||||
let proba = Math.random();
|
|
||||||
if (proba < 0.33)
|
|
||||||
message = markForTranslation("Here is a gift for %(_player_)s, make a good use of it.");
|
|
||||||
else if (proba < 0.66)
|
|
||||||
message = markForTranslation("I see you are in a bad situation %(_player_)s, I hope this will help.");
|
|
||||||
else
|
|
||||||
message = markForTranslation("I can help you this time %(_player_)s, but try to assemble more resources in the future.");
|
|
||||||
|
|
||||||
Engine.PostCommand(PlayerID, {
|
Engine.PostCommand(PlayerID, {
|
||||||
"type": "aichat",
|
"type": "aichat",
|
||||||
"message": "/allies " + message,
|
"message": "/allies " + pickRandom(this.sentTributeMessages),
|
||||||
"translateMessage": true,
|
"translateMessage": true,
|
||||||
"translateParameters": ["_player_"],
|
"translateParameters": ["_player_"],
|
||||||
"parameters": { "_player_": player }
|
"parameters": { "_player_": player }
|
||||||
@ -89,18 +98,9 @@ m.chatSentTribute = function(gameState, player)
|
|||||||
|
|
||||||
m.chatRequestTribute = function(gameState, resource)
|
m.chatRequestTribute = function(gameState, resource)
|
||||||
{
|
{
|
||||||
let message;
|
|
||||||
let proba = Math.random();
|
|
||||||
if (proba < 0.33)
|
|
||||||
message = markForTranslation("I am in need of %(resource)s, can you help? I will make it up to you.");
|
|
||||||
else if (proba < 0.66)
|
|
||||||
message = markForTranslation("I would participate more efficiently in our common war effort if you could provide me some %(resource)s.");
|
|
||||||
else
|
|
||||||
message = markForTranslation("If you have some %(resource)s excess, that would help me strengthen my army.");
|
|
||||||
|
|
||||||
Engine.PostCommand(PlayerID, {
|
Engine.PostCommand(PlayerID, {
|
||||||
"type": "aichat",
|
"type": "aichat",
|
||||||
"message": "/allies " + message,
|
"message": "/allies " + pickRandom(this.requestTributeMessages),
|
||||||
"translateMessage": true,
|
"translateMessage": true,
|
||||||
"translateParameters": { "resource": "withinSentence" },
|
"translateParameters": { "resource": "withinSentence" },
|
||||||
"parameters": { "resource": gameState.sharedScript.resourceInfo.names[resource] }
|
"parameters": { "resource": gameState.sharedScript.resourceInfo.names[resource] }
|
||||||
@ -109,31 +109,20 @@ m.chatRequestTribute = function(gameState, resource)
|
|||||||
|
|
||||||
m.chatNewTradeRoute = function(gameState, player)
|
m.chatNewTradeRoute = function(gameState, player)
|
||||||
{
|
{
|
||||||
let message;
|
|
||||||
let proba = Math.random();
|
|
||||||
if (proba < 0.5)
|
|
||||||
message = markForTranslation("I have set up a new route with %(_player_)s. Trading will be profitable for all of us.");
|
|
||||||
else
|
|
||||||
message = markForTranslation("A new trade route is set up with %(_player_)s. Take your share of the profits.");
|
|
||||||
|
|
||||||
Engine.PostCommand(PlayerID, {
|
Engine.PostCommand(PlayerID, {
|
||||||
"type": "aichat",
|
"type": "aichat",
|
||||||
"message": "/allies " + message,
|
"message": "/allies " + pickRandom(this.newTradeRouteMessages),
|
||||||
"translateMessage": true,
|
"translateMessage": true,
|
||||||
"translateParameters": ["_player_"],
|
"translateParameters": ["_player_"],
|
||||||
"parameters": { "_player_": player }
|
"parameters": { "_player_": player }
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
m.chatNewPhase = function(gameState, phase, started)
|
m.chatNewPhase = function(gameState, phase, status)
|
||||||
{
|
{
|
||||||
let message = started ?
|
|
||||||
markForTranslation("I am advancing to the %(phase)s.") :
|
|
||||||
markForTranslation("I have reached the %(phase)s.");
|
|
||||||
|
|
||||||
Engine.PostCommand(PlayerID, {
|
Engine.PostCommand(PlayerID, {
|
||||||
"type": "aichat",
|
"type": "aichat",
|
||||||
"message": "/allies " + message,
|
"message": "/allies " + pickRandom(this.newPhaseMessages[status]),
|
||||||
"translateMessage": true,
|
"translateMessage": true,
|
||||||
"translateParameters": ["phase"],
|
"translateParameters": ["phase"],
|
||||||
"parameters": { "phase": phase }
|
"parameters": { "phase": phase }
|
||||||
@ -144,7 +133,7 @@ m.chatNewDiplomacy = function(gameState, player, newDiplomaticStance)
|
|||||||
{
|
{
|
||||||
Engine.PostCommand(PlayerID, {
|
Engine.PostCommand(PlayerID, {
|
||||||
"type": "aichat",
|
"type": "aichat",
|
||||||
"message": API3.PickRandom(this.chatNewDiplomacyMessages[newDiplomaticStance]),
|
"message": pickRandom(this.newDiplomacyMessages[newDiplomaticStance]),
|
||||||
"translateMessage": true,
|
"translateMessage": true,
|
||||||
"translateParameters": ["_player_"],
|
"translateParameters": ["_player_"],
|
||||||
"parameters": { "_player_": player }
|
"parameters": { "_player_": player }
|
||||||
|
@ -408,14 +408,14 @@ m.HQ.prototype.checkEvents = function (gameState, events, queues)
|
|||||||
m.HQ.prototype.OnTownPhase = function(gameState)
|
m.HQ.prototype.OnTownPhase = function(gameState)
|
||||||
{
|
{
|
||||||
let phaseName = gameState.getTemplate(gameState.townPhase()).name();
|
let phaseName = gameState.getTemplate(gameState.townPhase()).name();
|
||||||
m.chatNewPhase(gameState, phaseName, true);
|
m.chatNewPhase(gameState, phaseName, "started");
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Called by the "city phase" research plan once it's started */
|
/** Called by the "city phase" research plan once it's started */
|
||||||
m.HQ.prototype.OnCityPhase = function(gameState)
|
m.HQ.prototype.OnCityPhase = function(gameState)
|
||||||
{
|
{
|
||||||
let phaseName = gameState.getTemplate(gameState.cityPhase()).name();
|
let phaseName = gameState.getTemplate(gameState.cityPhase()).name();
|
||||||
m.chatNewPhase(gameState, phaseName, true);
|
m.chatNewPhase(gameState, phaseName, "started");
|
||||||
};
|
};
|
||||||
|
|
||||||
/** This code trains citizen workers, trying to keep close to a ratio of worker/soldiers */
|
/** This code trains citizen workers, trying to keep close to a ratio of worker/soldiers */
|
||||||
@ -2113,7 +2113,7 @@ m.HQ.prototype.update = function(gameState, queues, events)
|
|||||||
else if (this.currentPhase == 3)
|
else if (this.currentPhase == 3)
|
||||||
phaseName = gameState.getTemplate(gameState.cityPhase()).name();
|
phaseName = gameState.getTemplate(gameState.cityPhase()).name();
|
||||||
|
|
||||||
m.chatNewPhase(gameState, phaseName, false);
|
m.chatNewPhase(gameState, phaseName, "completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.numActiveBase() > 0)
|
if (this.numActiveBase() > 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user