131 lines
4.6 KiB
C#
131 lines
4.6 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class ParameterContainer : MonoBehaviour
|
||
|
{
|
||
|
public GameObject targetConObj;
|
||
|
public GameObject blockConObj;
|
||
|
public GameObject agentObj;
|
||
|
private TargetController targetCon;
|
||
|
private SceneBlockContainer blockCont;
|
||
|
private float agentDistance;
|
||
|
private int agentInArea;
|
||
|
|
||
|
|
||
|
[Header("Env")]
|
||
|
public bool lockMouse = false;
|
||
|
public float Damage = 50; // damage to enemy
|
||
|
public float fireRate = 0.5f;
|
||
|
public int enemyNum = 3;
|
||
|
public int timeLimit = 30;
|
||
|
public bool lockCameraX = false;
|
||
|
public bool lockCameraY = true;
|
||
|
public bool chartOn = false;
|
||
|
|
||
|
|
||
|
[Header("Dynamic Defaut Rewards")]
|
||
|
[Tooltip("Hit Enemy reward")]
|
||
|
public float hitRewardDefault = 30.0f;
|
||
|
[Tooltip("Episode Win reward")]
|
||
|
public float winRewardDefault = 50.0f;
|
||
|
[Tooltip("Enemy down reward")]
|
||
|
public float killRewardDefault = 40.0f;
|
||
|
[Tooltip("Enemy down in area Reward")]
|
||
|
public float killInAreaEnemyRewardDefault = 80.0f;
|
||
|
[Tooltip("stay in firebasesArea reward")]
|
||
|
public float inAreaRewardDefault = 1.0f;
|
||
|
[Tooltip("free left time bonus reward. ALLR + leftTime * r")]
|
||
|
public float freeTimeBonusPerSec = 1.0f;
|
||
|
[Tooltip("target left time bonus reward. ALLR + leftTime * r")]
|
||
|
public float targetTimeBonusPerSec = 3.0f;
|
||
|
[Tooltip("in area left time bonus reward. ALLR + leftTime * r")]
|
||
|
public float areaTimeBonusPerSec = 1.0f;
|
||
|
[Tooltip("distance reward reward = r*(1-(nowDis/startDis))")]
|
||
|
public float distanceReward = 1.0f;
|
||
|
|
||
|
[Header("Dynamic Rewards")]
|
||
|
[Tooltip("Hit Enemy reward")]
|
||
|
public float hitReward = 30.0f;
|
||
|
[Tooltip("Enemy down reward")]
|
||
|
public float killReward = 40.0f;
|
||
|
[Tooltip("Episode Win reward")]
|
||
|
public float winReward = 50.0f;
|
||
|
[Tooltip("Enemy down in area Reward")]
|
||
|
public float killInAreaEnemyReward = 80.0f;
|
||
|
[Tooltip("stay in firebasesArea reward")]
|
||
|
public float inAreaReward = 1.0f;
|
||
|
|
||
|
|
||
|
|
||
|
[Header("Static Rewards")]
|
||
|
[Tooltip("Nothing happened reward")]
|
||
|
public float nonReward = -0.05f;
|
||
|
[Tooltip("Episode Lose reward")]
|
||
|
public float loseReward = -0.05f;
|
||
|
[Tooltip("Agent Do shoot action reward")]
|
||
|
public float shootReward = -0.1f;
|
||
|
[Tooltip("Agent Do shoot action but gun is not read")]
|
||
|
public float shootWithoutReadyReward = -0.15f;
|
||
|
[Tooltip("Kill bonus reward stack to nothing happend reward")]
|
||
|
public float killBonusReward = 0.0f;
|
||
|
[Header("Penalty Rewards")]
|
||
|
[Tooltip("Speed Penalty Reward")]
|
||
|
public float speedPanalty = 0f;
|
||
|
[Tooltip("view Panalty Reward")]
|
||
|
public float viewPanalty = 0f;
|
||
|
|
||
|
private float targetTimeBonus = 0f;
|
||
|
private float areaTimeBonus = 0f;
|
||
|
private float freeTimeBonus = 0f;
|
||
|
private float targetInAreaTime = 0f;
|
||
|
private float lastFrameTime = 0f;
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
targetCon = targetConObj.GetComponent<TargetController>();
|
||
|
blockCont = blockConObj.GetComponent<SceneBlockContainer>();
|
||
|
areaTimeBonus = areaTimeBonusPerSec * timeLimit;
|
||
|
freeTimeBonus = freeTimeBonusPerSec * timeLimit;
|
||
|
targetTimeBonus = targetTimeBonusPerSec * timeLimit;
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
if (targetCon.targetTypeInt != (int)TargetController.Targets.Free)
|
||
|
{
|
||
|
(agentDistance, agentInArea) = blockCont.getAgentTargetDistanceAndInside(agentObj.transform.position);
|
||
|
// 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;
|
||
|
}
|
||
|
|
||
|
hitReward = hitRewardDefault + freeTimeBonus;
|
||
|
killReward = killRewardDefault + freeTimeBonus;
|
||
|
winReward = winRewardDefault + targetTimeBonus;
|
||
|
killInAreaEnemyReward = killInAreaEnemyRewardDefault + targetTimeBonus;
|
||
|
inAreaReward = inAreaRewardDefault + areaTimeBonus;
|
||
|
}
|
||
|
|
||
|
public void resetTimeBonusReward()
|
||
|
{
|
||
|
areaTimeBonus = areaTimeBonusPerSec * timeLimit;
|
||
|
freeTimeBonus = freeTimeBonusPerSec * timeLimit;
|
||
|
targetInAreaTime = 0f;
|
||
|
}
|
||
|
}
|