Variable Projectile Velocity

Started by A_Soft_Machine_Man, January 30, 2017, 06:34:26 PM

Previous topic - Next topic

A_Soft_Machine_Man

Hey guys,

So I'm trying to get into modding for myself from scratch, rather than just altering someone else's assets to suit my own tastes. I ultimately have two ideas in mind, one I'm 99% certain will require some C# trickery while the second may be (hopefully) managed with only a little work in XML.

Long story short is I want to add in variable projectile velocity and an armor set which allows for short range teleportation.

Focusing on the former, I know Plymouth already made a thread about it but got no replies. My question is can it be done purely in XML, or would it require some baseline alterations to projectile behavior in C#?

As for the latter, I know this will require some C# trickery. The basic Idea I have is that the pawn wearing the armor set would have a commanded ability to teleport within a limited radius (think the standard command for directed shooting, but instead instantly altering the pawn's tile position). Any and all help/advice would be extremely appreciated

RawCode

this is not "do it for me" section.

please provide your data (xml) and logic (dll\c# trickery) and information about what is wrong, exception trace (as text, photo of monitor is not acceptable) if any and other useful information.

if you don't know where to start or unable to start for any reason, please explain what you had checked and what research you had done so far.

if you did nothing, completely nothing, no reading of core XML, no reading of game logic, this is really good moment to start.

read fully def of any vanilla weapon, fully and completely.
then read game logic to determinate, where "projectile speed" is stored and how it's used internally by game engine.

after that, you likely will get some clues about how to start.

A_Soft_Machine_Man

#2
Quote from: RawCode on January 30, 2017, 09:20:28 PM

if you don't know where to start or unable to start for any reason, please explain what you had checked and what research you had done so far.

Right, my bad. So far I have done most of my modding in XVM. Since I know each gun defines its projectile speed separate of the BaseBullet parent def, I simply just tried adding some defs using the same language of the accuracy modifiers, basically hoping to see if there was a preexisting class in the Assembly. So the end result was:

<ThingDef ParentName="BaseBullet">
    <defName>Bullet_Pistol</defName>
    <label>pistol bullet</label>
    <graphicData>
      <texPath>Things/Projectile/Bullet_Small</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <projectile>
      <flyOverhead>false</flyOverhead>
      <damageDef>Bullet</damageDef>
      <DamageAmountBase>9</DamageAmountBase>
      <Speed>55</Speed>
      <SpeedTouch>0.99</SpeedTouch>
      <SpeedShort>0.75</SpeedShort>
      <SpeedMedium>0.55</SpeedMedium>
      <SpeedLong>0.35</SpeedLong>
       </projectile>
  </ThingDef>
  <ThingDef ParentName="BaseHumanMakeableGun">
    <defName>Gun_Pistol</defName>
    <label>pistol</label>
    <description>Ancient pattern automatic pistol. Weak and short range, but quick.</description>
    <graphicData>
      <texPath>Things/Item/Equipment/WeaponRanged/Pistol</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <soundInteract>InteractPistol</soundInteract>
    <statBases>
      <WorkToMake>15000</WorkToMake>
      <Mass>1.2</Mass>
      <AccuracyTouch>0.91</AccuracyTouch>
      <AccuracyShort>0.71</AccuracyShort>
      <AccuracyMedium>0.50</AccuracyMedium>
      <AccuracyLong>0.32</AccuracyLong>
      <RangedWeapon_Cooldown>1.26</RangedWeapon_Cooldown>
    </statBases>
    <costList>
      <Steel>30</Steel>
      <Component>2</Component>
    </costList>
    <verbs>
      <li>
        <verbClass>Verb_Shoot</verbClass>
        <hasStandardCommand>true</hasStandardCommand>
        <projectileDef>Bullet_Pistol</projectileDef>
        <warmupTime>0.3</warmupTime>
        <range>24</range>
        <soundCast>ShotPistol</soundCast>
        <soundCastTail>GunTail_Light</soundCastTail>
        <muzzleFlashScale>9</muzzleFlashScale>
      </li>
    </verbs>
  </ThingDef>
       
Just as an experiment. While the new XML defs didn't force any errors in a completely Vanilla load, it had no effect. Seeing this, I knew that meant that the new defs were not defined in the assembly. So, taking a look I have seen that the Assembly defines projectile speed as:

//Verse.ProjectileProperties
public float speed =4f

And that there are separate classes for accuracy modifiers in both the VerbProperties and StateDefOf. Defined in both cases as:

public float accuracy[range] = 1f

Now, I'll fully admit to being functionally illiterate in C#, so I didn't know how I would implement the new definitions for range modifiers on speed without causing conflict between the base class and the new classes. As far as I am aware, no mod so far has altered or added to the projectile velocity class in such a way, so that's why I was hoping someone more experience in C# might have some ideas on how I could properly implement them.




RawCode

Quoteilliterate in C#
google + c# + learning in 5 minutes (or something similar)

after that, google + dnspy

after that dnspy + assemblycsharp + Verb_Shoot

A_Soft_Machine_Man

Quote from: RawCode on February 01, 2017, 12:34:34 AM
after that dnspy + assemblycsharp + Verb_Shoot

Right, so I've finally had the free time to actually look over the assemblies in depth. My question now is why would  I mod into the Verb class rather than to the ProjectileProperties class? While the private, floated assemblies for accuracy are defined in Verb, the preexisting speed assembly is defined in ProjectileProperties. Given that the XML defs for projectiles exist independent of the XML defs for the gun (or whatever is using the verb command to shoot) would it not make more sense for me to mod around the preexisting assembly? 

RawCode

if you know better, how to make variable velocity, why are you asking, just do it!