armordamagematrix <- matrix(0,nrow=5,ncol=10)
b <- matrix(0,nrow=5,ncol=5)
b[1:5,2:4] <- 1/30
b[2:4,1:5] <- 1/30
b[2:4,2:4] <- 1/15
normaldistpoints <- c(0.022,0.136,0.341,0.341,0.136,0.022)
#ships -
#ship, hullhp, shieldregen, shieldmax, startingarmor, name
glimmer <- c(1500, 250/0.6, 2500/0.6, 200, "glimmer")
brawlerlp <- c(2000, 500/0.8, 3000/0.8, 450, "brawlerlp")
vanguard <- c(3000, 150, 2000, 600, "vanguard")
tempest <- c(1250, 225/0.6, 2500/0.6, 200, "tempest")
medusa <- c(3000,400/0.6,6000/0.6,300, "medusa")
hammerhead <- c(5000,250/0.8,4200/0.8,500, "hammerhead")
enforcer <- c(4000,200,4000,900, "enforcer")
dominator <- c(14000, 500, 10000, 1500, "dominator")
fulgent <- c(5000,300/0.6,5000/0.6,450,"fulgent")
brilliant <- c(8000,600/0.6,10000/0.6,900,"brilliant")
radiant <- c(20000,1500/0.6,25000/0.6,1500,"radiant")
onslaught <- c(20000,600,17000,1750,"onslaught")
aurora <- c(8000,800/0.8,11000/0.8,800, "aurora")
paragon <- c(18000,1250/0.6,25000/0.6,1500,"paragon")
conquest <- c(12000,1200/1.4,20000/1.4,1200,"conquest")
champion <- c(10000,550/0.8,10000/0.8,1250, "champion")
ships <- list(glimmer, brawlerlp, vanguard, tempest, medusa, hammerhead, enforcer, dominator, fulgent, brilliant,radiant,onslaught,aurora,paragon,conquest,champion)
for (f in 1:length(ships)){
ship <- ships[[f]]
shipname <- ship[[5]]
ship <- as.double(ship[1:4])
for (i in 1:6) {
armordamagematrix[,i:(i+4)] <- armordamagematrix[,i:(i+4)]+b*normaldistpoints
}
armordamage <- function(damage, armor, startingarmor) damage*(max(0.15,damage/(damage+max(0.05*startingarmor,armor))))
armordamageselectivereduction <- function(damage, armor,useminarmor,startingarmor) {
if(useminarmor == 0){
if(armor == 0) {return (damage)}
return(damage*(max(0.15,damage/(damage+armor))))
}
else{
return(damage*(max(0.15,damage/(damage+0.05*startingarmor/15))))
}
}
#squall fires 2 missiles / sec for 10 secs, then recharges for 10 secs
squalltics <- c(2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0)
#locust fires 10 missiles / sec for 4 secs, then recharges for 5 secs
locusttics <- c(10,10,10,10,0,0,0,0,0)
#hurricane fires 9 missiles every 15 seconds
hurricanetics <- c(9,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
#harpoon pod fires 4 missiles in 1 second, then recharges for 8 seconds (in reality 8.25)
harpoontics <- c(4,0,0,0,0,0,0,0,0)
#sabot pod fires 2*5 missiles, then recharges for 8 seconds (in reality 8.75 seconds and firing time is .5 seconds)
sabottics <- c(10,0,0,0,0,0,0,0,0)
#gauss fires 1 shot, then charges for 1 second
gausstics <- c(1,0)
#hephaestus fires 4 shots / sec
hephaestustics <- c(4)
#mark ix fires 4 shots every 3 seconds, taking .4 seconds for the burst, so 20 shots / 17 seconds in bursts of 4
markixtics <- c(4,0,0,4,0,0,4,0,0,4,0,0,0,4,0,0,0)
#mjolnir fires 4 shots per 3 seconds
mjolnirtics <- c(1,1,2,1,2,1,2,1,1)
#hellbore fires 1 shot per 4 seconds
hellboretics <- c(1,0,0,0)
#storm needler fires 10 shots per second
stormneedlertics <- c(10)
#arbalest fires 1 shot every 1.2 seconds, so 5 shots / 6 seconds
arbalesttics <- c(1,1,1,0,1,1)
arbalest <- list(200, 2, arbalesttics, "Arbalest")
#heavy mauler fires a burst of 3, taking .9 seconds to do so, then recharges for 4.5 seconds. So total of 3 shots / 5.4 seconds, so total of 15 shots / 27 seconds in bursts of 3.
heavymaulertics <- c(3,0,0,0,0,0,3,0,0,0,0,3,0,0,0,0,3,0,0,0,0,3,0,0,0,0,0)
heavymauler <- list(200,0.5,heavymaulertics, "Heavy Mauler")
#heavy autocannon takes .6 seconds to fire a burst, then recharges for 1 second. So 3 shots / 1.6 secs, so 15 shots / 8 secs in bursts
hactics <- c(3,0,3,3,0,3,3,0)
hac <- list(100, 2, hactics, "Heavy Autocannon")
hvdtics <- c(1,0,0)
hvd <- list(275,2,hvdtics,"Hypervelocity Driver")
#heavy needler fires a burst of 30 needles with 0.05 sec intervals (1.5 sec) and then recharges for 4.55 sec (round to 4.5 sec)
needlertics <- c(20,10,0,0,0,0)
needler <- list(50,2,needlertics,"Heavy Needler")
#heavy mortar fires a burst of 2 rounds, taking .6 seconds to do so, then recharges for .7 seconds. So a total of 2 rounds every 1.3 seconds, so 20 rounds / 13 seconds in bursts of 2.
mortartics <- c(2,2,0,2,2,2,2,0,2,2,2,0,2)
mortar <- list(110,0.5,mortartics, "Heavy Mortar")
#damage per shot, damage type (2=kinetic, 0.5=he, 0.25=frag, 1=energy), tics, weapon name
squall <- list(250, 2, squalltics, "Squall")
locust <- list(200, 0.25, locusttics, "Locust")
hurricane <- list(500, 0.5, hurricanetics, "Hurricane")
harpoon <- list(750, 0.5, harpoontics, "Harpoon")
sabot <- list(200, 2, sabottics, "Sabot")
gauss <- list(700, 2, gausstics, "Gauss")
hephaestus <- list(120, 0.5, hephaestustics, "Hephaestus")
markix <- list(200, 2, markixtics, "Mark IX")
mjolnir <- list(400, 1, mjolnirtics, "Mjolnir")
hellbore <- list(750, 0.5, hellboretics, "Hellbore")
stormneedler <- list(50, 2, stormneedlertics, "Storm Needler")
dummy <- list(0,0,c(0),"")
weapon1 <- squall
weapon2 <- squall
weapon3 <- harpoon
weapon4 <- harpoon
weapon5 <- mjolnir
weapon6 <- mjolnir
weapon1choices <- list(squall)
weapon2choices <- list(squall)
weapon3choices <- list(harpoon)
weapon4choices <- list(harpoon)
weapon5choices <- list(gauss, markix, mjolnir, hellbore, hephaestus, stormneedler)
weapon6choices <- list(gauss, markix, mjolnir, hellbore, hephaestus, stormneedler)
weapon7choices <- list(arbalest, heavymauler, hac, hvd, needler, mortar)
weapon8choices <- list(arbalest, heavymauler, hac, hvd, needler, mortar)
timeseriesarray <- data.frame(matrix(ncol = 7,nrow=0))
timetokill=0
shieldblock <- 0
shielddamageattimepoint <- function(weapon, timepoint){
nohits <- weapon[[3]][(timepoint %% (length(weapon[[3]])))+1]
if (nohits == 0) {return(0)} else {
return(weapon[[1]]*nohits)
}
}
damageattimepoint <- function(weapon, timepoint, armor, useminarmor, startingarmor, hitx, hity){
# vectors in R are indexed starting from 1
nohits <- weapon[[3]][(timepoint %% (length(weapon[[3]])))+1]
if (nohits == 0) {return(0)} else {
damagesum <- 0
for (i in 1:nohits) {
damagesum <- damagesum + armordamageselectivereduction(weapon[[1]]*armordamagematrix[hitx,hity],armor,useminarmor,startingarmor)
}
return(damagesum)
}
}
timeseries <- function(timepoint, shieldhp, armorhp, hullhp, shieldregen, shieldmax, startingarmor,armormatrix){
#are we using shield to block?
shieldblock <- 0
hulldamage <- 0
if(hullhp > 0){} else {shieldhp <- 0}
useminarmor <- 0
#are we using the 5% minimum armor rule? deduce this by applying a weighted average of armor
if(weighted.mean(armormatrix,armordamagematrix) <= startingarmor/15*0.05){useminarmor <- 1
}
#1. shields. if shieldhp is sufficient, use shield to block
if (weapon1[[4]] !=""){
weapon1mult <- unlist(weapon1[2])
if (shieldhp > shielddamageattimepoint(weapon1, timepoint)*weapon1mult){
shieldhp <- shieldhp - shielddamageattimepoint(weapon1, timepoint)*weapon1mult
shieldhp <- max(shieldhp, 0)
if(shielddamageattimepoint(weapon1,timepoint) > 0) {shieldblock <- 1}
} else {
#if you did not use shield to block, regenerate flux
#2. armor and hull
if(unlist(weapon1[2])==0.25){weapon1mult = 0.25} else {weapon1mult= 1 / unlist(weapon1[2])}
#2.1. damage armor and hull
hulldamage <- 0
for (j in 2:9){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon1mult*damageattimepoint(weapon1, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon1mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon1mult*damageattimepoint(weapon1, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in 2:9){
for (i in c(1,5)){
hulldamage <- hulldamage+max(0,weapon1mult*damageattimepoint(weapon1, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon1mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon1mult*damageattimepoint(weapon1, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in c(1,10)){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon1mult*damageattimepoint(weapon1, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon1mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon1mult*damageattimepoint(weapon1, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
hullhp <- hullhp - hulldamage
hullhp <- max(hullhp, 0)
armorhp <- sum(armormatrix)/(46/15)
if(hullhp==0) armorhp <- 0
}
}
#repeat for other weapons
if (weapon2[[4]] !=""){
weapon2mult <- unlist(weapon2[2])
if (shieldhp > shielddamageattimepoint(weapon2, timepoint)*weapon2mult){
shieldhp <- shieldhp - shielddamageattimepoint(weapon2, timepoint)*weapon2mult
shieldhp <- max(shieldhp, 0)
if(shielddamageattimepoint(weapon2,timepoint) > 0) {shieldblock <- 1}
} else {
if(unlist(weapon2[2])==0.25){weapon2mult = 0.25} else {weapon2mult= 1 / unlist(weapon2[2])}
hulldamage <- 0
for (j in 2:9){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon2mult*damageattimepoint(weapon2, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon2mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon2mult*damageattimepoint(weapon2, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in 2:9){
for (i in c(1,5)){
hulldamage <- hulldamage+max(0,weapon2mult*damageattimepoint(weapon2, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon2mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon2mult*damageattimepoint(weapon2, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in c(1,10)){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon2mult*damageattimepoint(weapon2, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon2mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-armordamagematrix[i,j]*weapon2mult*damageattimepoint(weapon2, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
hullhp <- hullhp - hulldamage
hullhp <- max(hullhp, 0)
armorhp <- sum(armormatrix)/(46/15)
if(hullhp==0) armorhp <- 0
}
}
if (weapon3[[4]] !=""){
weapon3mult <- unlist(weapon3[2])
if (shieldhp > shielddamageattimepoint(weapon3, timepoint)*weapon3mult){
shieldhp <- shieldhp - shielddamageattimepoint(weapon3, timepoint)*weapon3mult
shieldhp <- max(shieldhp, 0)
if(shielddamageattimepoint(weapon3,timepoint) > 0) {shieldblock <- 1}
} else {
if(unlist(weapon3[2])==0.25){weapon3mult = 0.25} else {weapon3mult= 1 / unlist(weapon3[2])}
hulldamage <- 0
for (j in 2:9){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon3mult*damageattimepoint(weapon3, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon3mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon3mult*damageattimepoint(weapon3, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in 2:9){
for (i in c(1,5)){
hulldamage <- hulldamage+max(0,weapon3mult*damageattimepoint(weapon3, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon3mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon3mult*damageattimepoint(weapon3, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in c(1,10)){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon3mult*damageattimepoint(weapon3, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon3mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon3mult*damageattimepoint(weapon3, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
hullhp <- hullhp - hulldamage
hullhp <- max(hullhp, 0)
armorhp <- sum(armormatrix)/(46/15)
if(hullhp==0) armorhp <- 0
}
}
if (weapon4[[4]] !=""){
weapon4mult <- unlist(weapon4[2])
if (shieldhp > shielddamageattimepoint(weapon4, timepoint)*weapon4mult){
shieldhp <- shieldhp - shielddamageattimepoint(weapon4, timepoint)*weapon4mult
shieldhp <- max(shieldhp, 0)
if(shielddamageattimepoint(weapon4,timepoint) > 0) {shieldblock <- 1}
} else {
if(unlist(weapon4[2])==0.25){weapon4mult = 0.25} else {weapon4mult= 1 / unlist(weapon4[2])}
hulldamage <- 0
for (j in 2:9){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon4mult*damageattimepoint(weapon4, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon4mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon4mult*damageattimepoint(weapon4, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in 2:9){
for (i in c(1,5)){
hulldamage <- hulldamage+max(0,weapon4mult*damageattimepoint(weapon4, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon4mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon4mult*damageattimepoint(weapon4, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in c(1,10)){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon4mult*damageattimepoint(weapon4, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon4mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon4mult*damageattimepoint(weapon4, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
hullhp <- hullhp - hulldamage
hullhp <- max(hullhp, 0)
armorhp <- sum(armormatrix)/(46/15)
if(hullhp==0) armorhp <- 0
}
}
if (weapon5[[4]] !=""){
weapon5mult <- unlist(weapon5[2])
if (shieldhp > shielddamageattimepoint(weapon5, timepoint)*weapon5mult){
shieldhp <- shieldhp - shielddamageattimepoint(weapon5, timepoint)*weapon5mult
shieldhp <- max(shieldhp, 0)
if(shielddamageattimepoint(weapon5,timepoint) > 0) {shieldblock <- 1}
} else {
if(unlist(weapon5[2])==0.25){weapon5mult = 0.25} else {weapon5mult= 1 / unlist(weapon5[2])}
hulldamage <- 0
for (j in 2:9){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon5mult*damageattimepoint(weapon5, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon5mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon5mult*damageattimepoint(weapon5, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in 2:9){
for (i in c(1,5)){
hulldamage <- hulldamage+max(0,weapon5mult*damageattimepoint(weapon5, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon5mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon5mult*damageattimepoint(weapon5, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in c(1,10)){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon5mult*damageattimepoint(weapon5, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon5mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon5mult*damageattimepoint(weapon5, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
hullhp <- hullhp - hulldamage
hullhp <- max(hullhp, 0)
armorhp <- sum(armormatrix)/(46/15)
if(hullhp==0) armorhp <- 0
}
}
if (weapon6[[4]] !=""){
weapon6mult <- unlist(weapon6[2])
if (shieldhp > shielddamageattimepoint(weapon6, timepoint)*weapon6mult){
shieldhp <- shieldhp - shielddamageattimepoint(weapon6, timepoint)*weapon6mult
shieldhp <- max(shieldhp, 0)
if(shielddamageattimepoint(weapon6,timepoint) > 0) {shieldblock <- 1}
} else {
if(unlist(weapon6[2])==0.25){weapon6mult = 0.25} else {weapon6mult= 1 / unlist(weapon6[2])}
hulldamage <- 0
for (j in 2:9){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon6mult*damageattimepoint(weapon6, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon6mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon6mult*damageattimepoint(weapon6, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in 2:9){
for (i in c(1,5)){
hulldamage <- hulldamage+max(0,weapon6mult*damageattimepoint(weapon6, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon6mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon6mult*damageattimepoint(weapon6, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in c(1,10)){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon6mult*damageattimepoint(weapon6, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon6mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon6mult*damageattimepoint(weapon6, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
hullhp <- hullhp - hulldamage
hullhp <- max(hullhp, 0)
armorhp <- sum(armormatrix)/(46/15)
if(hullhp==0) armorhp <- 0
}
}
if (weapon7[[4]] !=""){
weapon7mult <- unlist(weapon7[2])
if (shieldhp > shielddamageattimepoint(weapon7, timepoint)*weapon7mult){
shieldhp <- shieldhp - shielddamageattimepoint(weapon7, timepoint)*weapon7mult
shieldhp <- max(shieldhp, 0)
if(shielddamageattimepoint(weapon7,timepoint) > 0) {shieldblock <- 1}
} else {
if(unlist(weapon7[2])==0.25){weapon7mult = 0.25} else {weapon7mult= 1 / unlist(weapon7[2])}
hulldamage <- 0
for (j in 2:9){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon7mult*damageattimepoint(weapon7, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon7mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon7mult*damageattimepoint(weapon7, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in 2:9){
for (i in c(1,5)){
hulldamage <- hulldamage+max(0,weapon7mult*damageattimepoint(weapon7, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon7mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon7mult*damageattimepoint(weapon7, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in c(1,10)){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon7mult*damageattimepoint(weapon7, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon7mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon7mult*damageattimepoint(weapon7, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
hullhp <- hullhp - hulldamage
hullhp <- max(hullhp, 0)
armorhp <- sum(armormatrix)/(46/15)
if(hullhp==0) armorhp <- 0
}
}
if (weapon8[[4]] !=""){
weapon8mult <- unlist(weapon8[2])
if (shieldhp > shielddamageattimepoint(weapon8, timepoint)*weapon8mult){
shieldhp <- shieldhp - shielddamageattimepoint(weapon8, timepoint)*weapon8mult
shieldhp <- max(shieldhp, 0)
if(shielddamageattimepoint(weapon8,timepoint) > 0) {shieldblock <- 1}
} else {
if(unlist(weapon8[2])==0.25){weapon8mult = 0.25} else {weapon8mult= 1 / unlist(weapon8[2])}
hulldamage <- 0
for (j in 2:9){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon8mult*damageattimepoint(weapon8, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon8mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon8mult*damageattimepoint(weapon8, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in 2:9){
for (i in c(1,5)){
hulldamage <- hulldamage+max(0,weapon8mult*damageattimepoint(weapon8, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon8mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon8mult*damageattimepoint(weapon8, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
for (j in c(1,10)){
for (i in 2:4){
hulldamage <- hulldamage+max(0,weapon8mult*damageattimepoint(weapon8, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j)-armormatrix[i,j])/weapon8mult
armormatrix[i,j] <- max(0,armormatrix[i,j]-weapon8mult*damageattimepoint(weapon8, timepoint,armormatrix[i,j],useminarmor,startingarmor,i,j))
}}
hullhp <- hullhp - hulldamage
hullhp <- max(hullhp, 0)
armorhp <- sum(armormatrix)/(46/15)
if(hullhp==0) armorhp <- 0
}
}
if (shieldblock==0){shieldhp <- min(shieldmax,shieldhp+shieldregen)}
return(list(timepoint, shieldhp, armorhp, hullhp, shieldregen, shieldmax, startingarmor,armormatrix))
}
totaltime = 500
armorhp <- ship[4]
shieldhp <- ship[3]
hullhp <- ship[1]
shieldregen <- ship[2]
shieldmax <- ship[3]
armorhp <- ship[4]
startingarmor <- ship[4]
armormatrix <- matrix(ship[4]/15,nrow=5,ncol=10)
armormatrix[1,1] <-0
armormatrix[1,10] <-0
armormatrix[5,1] <-0
armormatrix[5,10] <- 0
timetokill <- 0
for (i in 1:length(weapon1choices)) {
weapon1<-weapon1choices[]
for (j in 1:length(weapon2choices)) {
weapon2<-weapon2choices[[j]]
for (k in 1:length(weapon3choices)) {
weapon3<-weapon3choices[[k]]
for (l in 1:length(weapon4choices)) {
weapon4<-weapon4choices[[l]]
for (m in 1:length(weapon5choices)) {
weapon5<-weapon5choices[[m]]
for (n in 1:length(weapon6choices)) {
weapon6<-weapon6choices[[n]]
for (o in 1:length(weapon7choices)) {
weapon7<-weapon7choices[
for (p in 1:length(weapon8choices)) {
weapon8<-weapon8choices[[p]]
for (t in 1:totaltime){
state <- timeseries(t,shieldhp,armorhp,hullhp,shieldregen,shieldmax,startingarmor,armormatrix)
shieldhp <- state[[2]]
armorhp <- state[[3]]
hullhp <- state[[4]]
flux <- shieldmax - shieldhp
armormatrix <- state[[8]]
if(hullhp == 0){flux <- 0
if (timetokill == 0){timetokill <- t
break}
}
}
if (timetokill ==0){timetokill <- NA}
tobind <- c(timetokill,unlist(weapon1[4]),unlist(weapon2[4]),unlist(weapon3[4]),unlist(weapon4[4]),unlist(weapon5[4]),unlist(weapon6[4]),unlist(weapon7[4]),unlist(weapon8[4]))
timeseriesarray <- rbind(timeseriesarray,tobind)
armorhp <- ship[4]
shieldhp <- ship[3]
hullhp <- ship[1]
shieldregen <- ship[2]
shieldmax <- ship[3]
armorhp <- ship[4]
startingarmor <- ship[4]
armormatrix <- matrix(ship[4]/15,nrow=5,ncol=10)
armormatrix[1,1] <-0
armormatrix[1,10] <-0
armormatrix[5,1] <-0
armormatrix[5,10] <- 0
timetokill <- 0
}
}
}
}
}
}
}
}
colnames(timeseriesarray) <- c("Timetokill", "Weapon1", "Weapon2", "Weapon3", "Weapon4", "Weapon5", "Weapon6", "Weapon7", "Weapon8")
write.table(timeseriesarray, file = "optimizeweapons.tsv", row.names=FALSE, sep="\t")
sortbytime <- timeseriesarray[order(as.integer(timeseriesarray$Timetokill)),]
write.table(sortbytime, file = paste("optimizeweaponsbytime",shipname,"medguns.txt", sep=""), row.names=FALSE, sep="\t")
}