2023-08-15 10:47:14 +00:00
|
|
|
using System.Collections.Generic;
|
2022-11-28 22:54:08 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class ParameterContainer : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject targetConObj;
|
|
|
|
public GameObject blockConObj;
|
|
|
|
public GameObject agentObj;
|
2023-08-15 10:47:14 +00:00
|
|
|
public GameObject hudObj;
|
2022-11-28 22:54:08 +00:00
|
|
|
private TargetController targetCon;
|
|
|
|
private SceneBlockContainer blockCont;
|
2023-07-08 14:22:31 +00:00
|
|
|
private StartSeneData startSceneData;
|
2023-08-15 10:47:14 +00:00
|
|
|
private MessageBoxController messageCon;
|
2022-11-28 22:54:08 +00:00
|
|
|
private float agentDistance;
|
|
|
|
private int agentInArea;
|
|
|
|
|
|
|
|
[Header("Env")]
|
|
|
|
public bool lockMouse = false;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
|
|
|
public float damage = 50; // damage to enemy
|
2022-11-28 22:54:08 +00:00
|
|
|
public float fireRate = 0.5f;
|
|
|
|
public int timeLimit = 30;
|
|
|
|
public bool lockCameraX = false;
|
|
|
|
public bool lockCameraY = true;
|
2023-07-11 10:32:28 +00:00
|
|
|
public bool spawnAgentInAllMap = true;
|
|
|
|
public int spinRecordMax = 40;
|
|
|
|
public float spinPenaltyThreshold = 10;
|
2022-12-07 21:24:51 +00:00
|
|
|
public float facingInviewEnemyDisCOEF = 0.5f;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
|
|
|
[Header("Dynamic Defaut Rewards")]
|
2022-12-01 10:52:52 +00:00
|
|
|
//[Tooltip("Hit Enemy reward")]
|
|
|
|
//public float hitRewardDefault = 60.0f;
|
2022-11-29 21:39:56 +00:00
|
|
|
[Tooltip("Free mode Hit Enemy reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float hitTargetRewardDefault = 25f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
//[Tooltip("Enemy down reward")]
|
|
|
|
//public float killRewardDefault = 60.0f;
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("Enemy down in area Reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float killTargetEnemyRewardDefault = 25f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("stay in firebasesArea reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float inAreaRewardDefault = 12f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("free left time bonus reward. ALLR + leftTime * r")]
|
|
|
|
public float freeTimeBonusPerSec = 1.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("target left time bonus reward. ALLR + leftTime * r")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float targetTimeBonusPerSec = 0.5f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("in area left time bonus reward. ALLR + leftTime * r")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float areaTimeBonusPerSec = 0.2f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("distance reward reward = r*(1-(nowDis/startDis))")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float distanceReward = 50.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2023-04-09 14:35:38 +00:00
|
|
|
[Tooltip("facing to Target distance reward reward = r*(1-(nowDis/startDis))")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float facingTargetReward = 10.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-29 21:39:56 +00:00
|
|
|
[Space(10)]
|
|
|
|
[Tooltip("Goto Win reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float goWinRewardDefault = 999f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-29 21:39:56 +00:00
|
|
|
[Tooltip("Attack Win reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float attackWinRewardDefault = 999f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-29 21:39:56 +00:00
|
|
|
[Tooltip("Defence Win reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float defenceWinRewardDefault = 999f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-29 21:39:56 +00:00
|
|
|
[Tooltip("free Win reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float freeWinRewardDefault = 999f;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
|
|
|
[Header("Static Rewards")]
|
|
|
|
[Tooltip("Nothing happened reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float nonReward = -1f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("Episode Lose reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float loseReward = -999f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("Agent Do shoot action reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float shootReward = -0.5f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Tooltip("Hit Not target Enemy reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float hitNonTargetReward = -5f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Tooltip("Not Target Enemy down reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float killNonTargetReward = -5f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("Agent Do shoot action but gun is not read")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float shootWithoutReadyReward = -1.15f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Tooltip("Kill bonus reward stack to nothing happend reward")]
|
|
|
|
public float killBonusReward = 0.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-05 05:56:18 +00:00
|
|
|
[Tooltip("Facing to enemy's reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float facingReward = 5f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-05 05:56:18 +00:00
|
|
|
[Tooltip("Shoot at target area but didn't hit enemy")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float shootTargetAreaReward = 10f;
|
2022-12-05 05:56:18 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
[Header("Penalty Rewards")]
|
2023-02-15 12:06:57 +00:00
|
|
|
[Tooltip("move Penalty Reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float movePenalty = 0.1f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-07 21:24:51 +00:00
|
|
|
[Tooltip("spiiiiiiin Panalty Reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float spinPenalty = 0.08f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-07 21:24:51 +00:00
|
|
|
[Tooltip("while move mouse a little bit's penalty")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float mousePenalty = 0.06f;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Header("Dynamic Rewards")]
|
|
|
|
[Tooltip("Free mode Hit Enemy reward")]
|
|
|
|
public float hitTargetReward = 60.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Tooltip("Enemy down in area Reward")]
|
|
|
|
public float killTargetEnemyReward = 80.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Tooltip("stay in firebasesArea reward")]
|
2023-07-11 10:32:28 +00:00
|
|
|
public float inAreaReward = 5.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Space(10)]
|
|
|
|
[Tooltip("go Win reward")]
|
|
|
|
public float goWinReward = 50.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Tooltip("attack Win reward")]
|
|
|
|
public float attackWinReward = 50.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Tooltip("defence Win reward")]
|
|
|
|
public float defenceWinReward = 50.0f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
[Tooltip("free Win reward")]
|
|
|
|
public float freeWinReward = 50.0f;
|
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
private float targetTimeBonus = 0f;
|
|
|
|
private float areaTimeBonus = 0f;
|
|
|
|
private float freeTimeBonus = 0f;
|
|
|
|
private float targetInAreaTime = 0f;
|
|
|
|
private float lastFrameTime = 0f;
|
|
|
|
|
2023-07-28 10:44:02 +00:00
|
|
|
[System.NonSerialized] public int gameMode; // 0 = trainning mode, 1 = play mode
|
2023-07-08 14:22:31 +00:00
|
|
|
[System.NonSerialized] public float attackProb = 0f;
|
|
|
|
[System.NonSerialized] public float gotoProb = 0f;
|
|
|
|
[System.NonSerialized] public float defenceProb = 0f;
|
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
targetCon = targetConObj.GetComponent<TargetController>();
|
|
|
|
blockCont = blockConObj.GetComponent<SceneBlockContainer>();
|
2023-08-15 10:47:14 +00:00
|
|
|
messageCon = hudObj.GetComponent<MessageBoxController>();
|
2022-11-28 22:54:08 +00:00
|
|
|
areaTimeBonus = areaTimeBonusPerSec * timeLimit;
|
|
|
|
freeTimeBonus = freeTimeBonusPerSec * timeLimit;
|
|
|
|
targetTimeBonus = targetTimeBonusPerSec * timeLimit;
|
2023-07-08 14:22:31 +00:00
|
|
|
try
|
|
|
|
{
|
2023-07-28 19:04:18 +00:00
|
|
|
// try get start scene data
|
2023-07-08 14:22:31 +00:00
|
|
|
startSceneData = GameObject.Find("StartSceneDataTransfer").GetComponent<StartSeneData>();
|
2023-08-15 10:47:14 +00:00
|
|
|
messageCon.PushMessage(
|
|
|
|
new List<string> { "ParameterContainer:", "StartSceneDataTransfer found!" },
|
|
|
|
new List<string> { "green", "white" });
|
2023-07-08 14:22:31 +00:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2023-08-08 16:11:25 +00:00
|
|
|
// if not found, find dummy StartSeneData
|
|
|
|
startSceneData = GameObject.Find("StartSceneDataTransferDummy").GetComponent<StartSeneData>();
|
2023-08-15 10:47:14 +00:00
|
|
|
messageCon.PushMessage(
|
|
|
|
new List<string> { "ParameterContainer:", "StartSceneDataTransfer not found!" },
|
|
|
|
new List<string> { "orange" });
|
2023-07-08 14:22:31 +00:00
|
|
|
}
|
2023-08-08 16:11:25 +00:00
|
|
|
gameMode = startSceneData.gameMode;
|
|
|
|
attackProb = startSceneData.attackProb;
|
|
|
|
gotoProb = startSceneData.gotoProb;
|
|
|
|
defenceProb = startSceneData.defenceProb;
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2023-06-29 06:18:10 +00:00
|
|
|
// get target distance and in area
|
|
|
|
if (targetCon.targetTypeInt is (int)SceneBlockContainer.Targets.Go or (int)SceneBlockContainer.Targets.Attack)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
2023-06-30 09:30:12 +00:00
|
|
|
(agentDistance, agentInArea) = blockCont.GetAgentTargetDistanceAndInside(agentObj.transform.position);
|
2022-11-28 22:54:08 +00:00
|
|
|
// attack goto or defence target
|
|
|
|
if (agentInArea == 1)
|
|
|
|
{
|
|
|
|
// agent out of area
|
|
|
|
targetInAreaTime += Time.time - lastFrameTime;
|
|
|
|
}
|
|
|
|
areaTimeBonus = areaTimeBonusPerSec * (targetCon.leftTime + targetInAreaTime);
|
|
|
|
freeTimeBonus = freeTimeBonusPerSec * targetCon.leftTime;
|
|
|
|
targetTimeBonus = targetTimeBonusPerSec * targetCon.leftTime;
|
|
|
|
lastFrameTime = Time.time;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// free target
|
|
|
|
areaTimeBonus = areaTimeBonusPerSec * targetCon.leftTime;
|
|
|
|
freeTimeBonus = freeTimeBonusPerSec * targetCon.leftTime;
|
|
|
|
targetTimeBonus = targetTimeBonusPerSec * targetCon.leftTime;
|
|
|
|
}
|
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
hitTargetReward = hitTargetRewardDefault + targetTimeBonus;
|
2022-11-29 21:39:56 +00:00
|
|
|
killTargetEnemyReward = killTargetEnemyRewardDefault + targetTimeBonus;
|
2022-11-28 22:54:08 +00:00
|
|
|
inAreaReward = inAreaRewardDefault + areaTimeBonus;
|
2022-11-29 21:39:56 +00:00
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
// Win Rewards
|
2022-12-03 08:42:51 +00:00
|
|
|
goWinReward = goWinRewardDefault;
|
|
|
|
attackWinReward = attackWinRewardDefault;
|
|
|
|
defenceWinReward = defenceWinRewardDefault;
|
|
|
|
freeWinReward = freeWinRewardDefault;
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 09:30:12 +00:00
|
|
|
public void ResetTimeBonusReward()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
areaTimeBonus = areaTimeBonusPerSec * timeLimit;
|
|
|
|
freeTimeBonus = freeTimeBonusPerSec * timeLimit;
|
|
|
|
targetInAreaTime = 0f;
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
}
|