深海远航吧 关注:575贴子:8,711
  • 42回复贴,共1

洲际核导弹。。。代码及设计注意事项

只看楼主收藏回复

哈喽小伙伴们好久不见,好久没玩这游戏了前几天逛了下贴吧发现吧友的作品都很棒,于是楼主也想做个作品出来分享。可是巨舰大炮我也不是很了解,所以看了下发现核弹头能用了威力还不错,所以造了个洲际核导弹。虽说威力不错但其实连常规导弹的威力都没达到……你见过哪个核弹头爆炸范围跟手榴弹一样的?逼得我非要让导弹直接命中才有威力,醉了


IP属地:广西1楼2016-06-05 11:15回复
    楼主测试用的导弹




    IP属地:广西2楼2016-06-05 11:21
    回复
      2025-06-30 07:01:31
      广告
      刚开始的时候导弹每次进入大气层就乱飞,让我以为代码有问题找了好久。结果在宇宙里就完美索敌,这才想起洲际导弹弹头进入大气层都是通过高速旋转平衡力矩的。这游戏也太科学了吧?!加了旋转后果然稳定多了。当然也可能导弹很重的话就会很稳定。
      第一阶段上升到巡航高度,一般要出大气层,不然阻力教您做人


      第二阶段到达目标上方空域

      第三阶段垂直撞击目标



      IP属地:广西3楼2016-06-05 11:24
      回复
        代码如下
        interflag=-1
        function calculate(I)
        I:Component_SetIntLogic(10,0,1)
        I:RequestThrustControl(0)
        TPI=I:GetTargetPositionInfo(0, 0)
        AZI=TPI.Azimuth
        ELE=TPI.Elevation
        LAV=I:GetLocalAngularVelocity()
        Roll=I:GetConstructRoll()
        sinr=math.sin(math.rad(Roll)) cosr=math.cos(math.rad(Roll))
        TIP=I:GetTargetInfo(0, 0).Position
        COM=I:GetConstructCenterOfMass()
        RP=TIP-COM
        AziRange2=RP.x^2+RP.z^2
        up=0 down=0 right=0 left=0
        cruisealtitude=600
        --初始阶段:垂直上升到2000以上高度
        if AziRange2<160000 then interflag=1 end
        if interflag<0 then
        FV=I:GetConstructForwardVector()
        if COM.y<cruisealtitude-50 then
        I:LogToHud("第一阶段:高度") I:LogToHud(COM.y)
        a=-math.deg(math.asin(math.sqrt(FV.x^2+FV.z^2)*sinr))
        b=math.deg(math.asin(math.sqrt(FV.x^2+FV.z^2)*cosr))
        if FV.y<0 then
        e=math.deg(math.acos(-FV.y))
        if b>0 then b=-e/(180-e)*b
        end
        if a>0 then a=-e/(180-e)*a
        end
        end
        --第二阶段:到达目标上空空间
        else I:LogToHud("第二阶段:距离") I:LogToHud(math.sqrt(AziRange2))
        cosb=(FV.x*RP.x+FV.y*(cruisealtitude-COM.y)+FV.z*RP.z)/math.sqrt(RP.x^2+(cruisealtitude-COM.y)^2+RP.z^2)
        rr=math.deg(math.asin(FV.y/math.sqrt(1-cosb^2)))
        if FV.z/FV.x<RP.z/RP.x then
        if FV.x*RP.x<0 then
        p=1
        else p=-1
        end
        else if FV.x*RP.x>0 then
        p=1
        else p=-1
        end
        end
        r2=Roll+p*(90+rr)
        if r2>180 then r2=r2-360 end
        if r2<-180 then r2=r2+360 end
        sinr2=math.sin(math.rad(r2)) cosr2=math.cos(math.rad(r2))
        a=-math.deg(math.asin(math.sqrt(1-cosb^2)*sinr2))
        b=math.deg(math.asin(math.sqrt(1-cosb^2)*cosr2))
        if cosb<0 then
        e=math.deg(math.asin(math.sqrt(1-cosb^2)))
        if b>0 then b=e/(180-e)*b
        end
        if a>0 then a=e/(180-e)*a
        end
        end
        end
        --第三阶段:俯冲垂直撞击
        else I:LogToHud("第三阶段:距离") I:LogToHud(TPI.Range) interflag=1
        RV=I:GetConstructRightVector() UV=I:GetConstructUpVector()
        cosa=(UV.x*RP.x+UV.y*RP.y+UV.z*RP.z)/math.sqrt(RP.x^2+RP.y^2+RP.z^2)
        cosb=(FV.x*RP.x+FV.y*RP.y+FV.z*RP.z)/math.sqrt(RP.x^2+RP.y^2+RP.z^2)
        cosc=(RV.x*RP.x+RV.y*RP.y+RV.z*RP.z)/math.sqrt(RP.x^2+RP.y^2+RP.z^2)
        if cosb>0 then
        a=math.abs(cosb)/(math.abs(cosb)+math.abs(cosc))*90
        b=math.abs(cosb)/(math.abs(cosb)+math.abs(cosa))*90
        else a=180-math.abs(cosb)/(math.abs(cosb)+math.abs(cosc))*90
        b=180-math.abs(cosb)/(math.abs(cosb)+math.abs(cosa))*90
        end
        if cosc>0 then a=-a end
        if cosa<0 then b=-b end
        end
        --消除偏角
        maxa=0.3 force1=1 force2=0.8
        if COM.y<400 then force2=0.3 maxa=0.1 end
        if a<0 then
        if LAV.y<maxa then
        right=force1
        else left=force2
        end
        else if LAV.y>-maxa then
        left=force1
        else right=force2
        end
        end
        if b>0 then
        if LAV.x>-maxa then
        up=force1
        else down=force2
        end
        else if LAV.x<maxa then
        down=force1
        else up=force2
        end
        end
        I:RequestThrustControl(8, right)
        I:RequestThrustControl(9, left)
        I:RequestThrustControl(10, up)
        I:RequestThrustControl(11, down)
        end
        function Update(I)
        I:TellAiThatWeAreTakingControl()
        if I:GetNumberOfTargets(0)>0 then
        calculate(I)
        else I:Component_SetIntLogic(10,0,0)
        end
        end
        其中第三阶段代码可以直接换成
        else I:LogToHud("第三阶段:距离") I:LogToHud(TPI.Range) interflag=1
        a=AZI b=ELE
        end
        因为这里的AZI ELE 似乎是根据建造的第一个方块来算的而不是几何或质量中心,所以我换成了三维坐标来算。结果发现是一样的?所以这里可以换回来直接a=AZI b=ELE


        IP属地:广西4楼2016-06-05 11:28
        收起回复
          设计注意:导弹要稍微长点,尽量前后都有转向推进器,加旋转。旋转方块我用过不好用,可能是我导弹太小。
          因为是比较简单的导航系统所以没有预判……毕竟现实中核导弹都是打定点的吧
          感兴趣的吧友可以继续研究更高级的形式和系统,我也设想过子母弹但是这里难道要用dockstation?
          有疑问的请新开一楼问


          IP属地:广西6楼2016-06-05 11:35
          回复
            设计比较幼稚,望大神勿喷


            IP属地:广西7楼2016-06-05 11:36
            回复
              话说这杀伤力来之哪里?


              IP属地:上海8楼2016-06-05 12:16
              收起回复


                IP属地:广西9楼2016-06-05 16:01
                回复
                  2025-06-30 06:55:31
                  广告
                  讲道理,这个核弹头还是有点威力的,不过嘛,,,,跟torpex一个水平吧。。。最近拿他做了个鱼雷,然后把我的BB侧舷炸了个大洞,包括了防雷突出部一直炸到轮机舱外一层铁板,哪怕再往里面1m也会。。。。可怕


                  IP属地:湖北10楼2016-06-06 10:34
                  收起回复
                    向会打代码的巨巨致敬w


                    IP属地:湖北11楼2016-07-10 18:03
                    回复
                      代码!贴吧果然牛人多


                      IP属地:内蒙古12楼2016-07-10 18:52
                      回复
                        哭瞎


                        IP属地:广东来自iPhone客户端13楼2016-07-12 08:08
                        回复