great scienstist does the job like original game (#1453)

This commit is contained in:
lishaoxia1985
2019-12-16 02:41:39 +08:00
committed by Yair Morgenstern
parent e937ea0af1
commit 418a4968a4
8 changed files with 65 additions and 43 deletions

View File

@ -13,6 +13,7 @@ import kotlin.collections.ArrayList
import kotlin.collections.HashSet
import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.min
class TechManager {
@Transient lateinit var civInfo: CivilizationInfo
@ -27,6 +28,7 @@ class TechManager {
@Transient var movementSpeedOnRoadsImproved=false
var freeTechs = 0
var recently8turnsScience = IntArray(8){0}
var techsResearched = HashSet<String>()
/* When moving towards a certain tech, the user doesn't have to manually pick every one. */
var techsToResearch = ArrayList<String>()
@ -40,6 +42,8 @@ class TechManager {
toReturn.freeTechs=freeTechs
toReturn.techsInProgress.putAll(techsInProgress)
toReturn.techsToResearch.addAll(techsToResearch)
toReturn.recently8turnsScience=recently8turnsScience.clone()
toReturn.overflowScience=overflowScience
return toReturn
}
@ -117,7 +121,43 @@ class TechManager {
return prerequisites.sortedBy { it.column!!.columnNumber }.map { it.name }
}
fun greatscientistgetScience(): Int {
// https://civilization.fandom.com/wiki/Great_Scientist_(Civ5)
return (recently8turnsScience.sum() * civInfo.gameInfo.gameParameters.gameSpeed.getModifier()).toInt()
}
fun recently8turnsScience() {
// Science greatscientist gets does not include Science from Polocies, Trade routes and City States.
var allcitiesScience = 0f
civInfo.cities.forEach{
val m= it.cityStats.baseStatList.values.map { it.science }.sum()
val n= it.cityStats.statPercentBonusList.filter { it.key!="Policies" }.values.map { it.science }.sum()
allcitiesScience += m*(1+n/100)
}
recently8turnsScience[civInfo.gameInfo.turns%8] = allcitiesScience.toInt()
}
fun hurryResearch() {
val currentTechnology = currentTechnologyName()
if (currentTechnology == null) return
techsInProgress[currentTechnology] = researchOfTech(currentTechnology) + greatscientistgetScience()
if (techsInProgress[currentTechnology]!! < costOfTech(currentTechnology))
return
// We finished it!
// http://www.civclub.net/bbs/forum.php?mod=viewthread&tid=123976
var overflowscience = techsInProgress[currentTechnology]!! - costOfTech(currentTechnology)
overflowScience += overflowScience(overflowscience)
addTechnology(currentTechnology)
}
fun overflowScience(overflowscience: Int): Int {
// http://www.civclub.net/bbs/forum.php?mod=viewthread&tid=123976
return min(overflowscience, max(civInfo.statsForNextTurn.science.toInt() * 5, getRuleset().Technologies[currentTechnologyName()]!!.cost))
}
fun nextTurn(scienceForNewTurn: Int) {
recently8turnsScience()
val currentTechnology = currentTechnologyName()
if (currentTechnology == null) return
techsInProgress[currentTechnology] = researchOfTech(currentTechnology) + scienceForNewTurn
@ -125,15 +165,14 @@ class TechManager {
val techsResearchedKnownCivs = civInfo.getKnownCivs().count { it.isMajorCiv() && it.tech.isResearched(currentTechnologyName()!!) }
val undefeatedCivs = UncivGame.Current.gameInfo.civilizations.count { it.isMajorCiv() && !it.isDefeated() }
techsInProgress[currentTechnology] = techsInProgress[currentTechnology]!! + ((1 + techsResearchedKnownCivs / undefeatedCivs.toFloat() * 0.3f)* overflowScience).toInt()
overflowScience = 0
}
if (techsInProgress[currentTechnology]!! < costOfTech(currentTechnology))
return
// We finished it!
// http://www.civclub.net/bbs/forum.php?mod=viewthread&tid=123976
overflowScience = techsInProgress[currentTechnology]!! - costOfTech(currentTechnology)
if(overflowScience > max(scienceForNewTurn * 5, getRuleset().Technologies[currentTechnology]!!.cost))
overflowScience = max(scienceForNewTurn * 5, getRuleset().Technologies[currentTechnology]!!.cost)
val overflowscience = techsInProgress[currentTechnology]!! - costOfTech(currentTechnology)
overflowScience = overflowScience(overflowscience)
addTechnology(currentTechnology)
}

View File

@ -12,7 +12,6 @@ import com.unciv.models.ruleset.Building
import com.unciv.models.ruleset.tr
import com.unciv.ui.pickerscreens.ImprovementPickerScreen
import com.unciv.ui.pickerscreens.PromotionPickerScreen
import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.worldscreen.WorldScreen
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
import java.util.*
@ -196,11 +195,11 @@ class UnitActions {
if (unit.name == "Great Scientist" && !unit.isEmbarked()) {
actionList += UnitAction("Discover Technology", unit.currentMovement >0
actionList += UnitAction("Hurry Research", unit.civInfo.tech.currentTechnologyName() != null
&& unit.currentMovement >0
) {
unit.civInfo.tech.freeTechs += 1
unit.civInfo.tech.hurryResearch()
unit.destroy()
worldScreen.game.setScreen(TechPickerScreen(true, unit.civInfo))
}.sound("chimes")
}

View File

@ -33,7 +33,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
"Automate" -> return ImageGetter.getUnitIcon("Great Engineer")
"Stop automation" -> return ImageGetter.getImage("OtherIcons/Stop")
"Found city" -> return ImageGetter.getUnitIcon(Constants.settler)
"Discover Technology" -> return ImageGetter.getUnitIcon("Great Scientist")
"Hurry Research" -> return ImageGetter.getUnitIcon("Great Scientist")
"Construct Academy" -> return ImageGetter.getImprovementIcon("Academy")
"Start Golden Age" -> return ImageGetter.getUnitIcon("Great Artist")
"Construct Landmark" -> return ImageGetter.getImprovementIcon("Landmark")