Author Topic: Algorithm for creating soldiers  (Read 4782 times)

Offline Vangrimar1

  • Colonel
  • ****
  • Posts: 143
    • View Profile
Algorithm for creating soldiers
« on: April 06, 2018, 03:29:01 pm »
Who can describe in detail how to add your soldier? Which files are used?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Algorithm for creating soldiers
« Reply #1 on: April 06, 2018, 03:32:26 pm »
What exactly do you mean by 'add your soldier'?  Do you mean creating a new soldier type that can be recruited?

Offline Vangrimar1

  • Colonel
  • ****
  • Posts: 143
    • View Profile
Re: Algorithm for creating soldiers
« Reply #2 on: April 06, 2018, 03:38:35 pm »
Exactly! :) It is desirable as detailed as possible. And then the method of trial and error does not work. :(

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8631
    • View Profile
Re: Algorithm for creating soldiers
« Reply #3 on: April 06, 2018, 03:43:08 pm »
1. Take the existing entry from "soldiers.rul" and copy it into your mod
2. change type from STR_SOLDIER to your new name, for example: STR_MY_SUPERSOLDIER
3. change the attributes (in this copied version) as you like
4. (optional) add a translation for STR_MY_SUPERSOLDIER via extraStrings

Offline Vangrimar1

  • Colonel
  • ****
  • Posts: 143
    • View Profile
Re: Algorithm for creating soldiers
« Reply #4 on: April 06, 2018, 03:54:20 pm »
It's clear. But I'm also interested in the possibility of changing the appearance and armor. I understand that need to change the categories "items", "armors", "extraSprites" .How can I do this? Can I use a specific code example?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Algorithm for creating soldiers
« Reply #5 on: April 06, 2018, 04:03:25 pm »
For appearances and armor, you should look at the examples in the armors ruleset in the folder common/xcom1/armors.rul - each armor defined there determines the look of the unit by calling a particular sprite sheet and inventory image, as well as defining which items in your base's stores is used for the armor.

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1510
    • View Profile
Re: Algorithm for creating soldiers
« Reply #6 on: April 06, 2018, 11:33:59 pm »
I can offer some code examples.



This code grants three new kinds of soldier, with variance to minStats, maxStats, and statCaps. The minStats sets the lowest value they can be generated with, maxStats sets the highest value they can be generated with, and statCaps sets the point at which they cease gaining experience and cannot train any higher. Note that the STR_ELITE has minimum attributes similar to the STR_SUPER_SOLDIER, however the elite shares the same attribute maximums as a basic soldier while the super soldier can get a bit higher. (My mod changes several basic soldier stat caps from 120 to 100.) This points to a difference in how these soldier types will pan out into the game. An elite is strong initially, but eventually is just the same as the rest of your soldiers except has a higher paycheck. The super soldier will always be stronger than other soldiers. Another interesting quirk is that the STR_PSI_PRODIGY has a minimum psiSkill above 0. This means they can use a psi amp without training.

The attribute choices you make on soldiers can have many effects on their design, and give you a huge array of options. You can also design armor suits that affect soldier attributes by either raising or lowering them, and I believe you can set armor types per soldier type to give them armor compatibilities, but I don't know how to do that.

Two of these soldiers have a technology requirement to unlock them. Once unlocked, they can be hired just like any other soldier. The psi prodigy requires techs which already exist in the game, but you would have to make a research entry for the super soldier or else it cannot be unlocked.
Code: [Select]
soldiers:
  - type: STR_PSIONIC_PRODIGY
    costBuy: 120000
    costSalary: 30000
    requires:
      - STR_PSI_LAB
      - STR_PSI_AMP
    minStats:
      tu: 40
      stamina: 30
      health: 15
      bravery: 10
      reactions: 20
      firing: 20
      throwing: 20
      strength: 10
      psiStrength: 60
      psiSkill: 8
      melee: 20
    maxStats:
      tu: 60
      stamina: 70
      health: 40
      bravery: 60
      reactions: 60
      firing: 70
      throwing: 70
      strength: 40
      psiStrength: 80
      psiSkill: 16
      melee: 70
    statCaps:
      tu: 75
      stamina: 100
      health: 60
      bravery: 100
      reactions: 100
      firing: 100
      throwing: 100
      strength: 60
      psiStrength: 80
      psiSkill: 80
      melee: 100
    armor: STR_NONE_UC
    standHeight: 22
    kneelHeight: 14
    femaleFrequency: 40
    soldierNames:
      - SoldierName/
    deathMale: [41, 42, 43]
    deathFemale: [44, 45, 46]
  - type: STR_ELITE
    costBuy: 80000
    costSalary: 40000
    minStats:
      tu: 53
      stamina: 50
      health: 30
      bravery: 30
      reactions: 40
      firing: 50
      throwing: 50
      strength: 27
      psiStrength: 40
      psiSkill: 0
      melee: 50
    maxStats:
      tu: 60
      stamina: 70
      health: 40
      bravery: 60
      reactions: 60
      firing: 70
      throwing: 70
      strength: 40
      psiStrength: 60
      psiSkill: 16
      melee: 70
    statCaps:
      tu: 75
      stamina: 100
      health: 60
      bravery: 100
      reactions: 100
      firing: 100
      throwing: 100
      strength: 60
      psiStrength: 60
      psiSkill: 60
      melee: 100
    armor: STR_NONE_UC
    standHeight: 22
    kneelHeight: 14
    femaleFrequency: 25
    soldierNames:
      - SoldierName/
    deathMale: [41, 42, 43]
    deathFemale: [44, 45, 46]
  - type: STR_SUPER_SOLDIER
    costBuy: 250000
    costSalary: 125000
    requires:
      - STR_SUPER_SOLDIERS
    minStats:
      tu: 57
      stamina: 60
      health: 35
      bravery: 40
      reactions: 50
      firing: 60
      throwing: 60
      strength: 33
      psiStrength: 50
      psiSkill: 0
      melee: 60
    maxStats:
      tu: 63
      stamina: 80
      health: 45
      bravery: 70
      reactions: 70
      firing: 80
      throwing: 80
      strength: 47
      psiStrength: 70
      psiSkill: 16
      melee: 80
    statCaps:
      tu: 80
      stamina: 110
      health: 65
      bravery: 110
      reactions: 110
      firing: 110
      throwing: 110
      strength: 65
      psiStrength: 70
      psiSkill: 70
      melee: 110
    armor: STR_NONE_UC
    standHeight: 22
    kneelHeight: 14
    femaleFrequency: 5
    soldierNames:
      - SoldierName/
    deathMale: [41, 42, 43]
    deathFemale: [44, 45, 46]



This code shows an example of making armor changes. The STR_SUPER_SOLDIER_UP is a special armor that can't be worn; its only purpose is to be visible in the UFOPedia. This is a way you can make a UFOPedia article detailing a given soldier class. The spriteInv setting is MAN_0M5, which is the sixth variation of the MAN_0 collection, which is the male unarmored/jumpsuit soldier. There are only 4 vanilla variations (MAN_0M0 through MAN0_M3) but you can add more as I have done, borrowing work from another artist or designing your own soldier graphics. These are set in the extraSprites section which I will get to further down in this post. The game will select soldier appearances from any of the available options in the category, while the armor must be set with a particular appearance. If you don't set one, it will default to #0, but you have the option to customize it further by deciding which soldier is wearing the armor in the UFOPedia.

The STR_PSI_DEFENSE_ARMOR_UC is a new armor type which can be researched, manufactured, and worn by soldiers. This means it has entries in the research, manufacture, and items sections in addition to ufopedia and armors sections. This code shows you all of the important lines to declare attributes for the armor in the armors section. Some of these don't have to be in your ruleset as they have default settings, but they may as well be there so that you can set each value to your liking.

At the bottom, you see STR_POWER_SUIT as a demonstration for how you can include very few attributes in your ruleset for an entry that exists elsewhere. The attributes declared here will override the corresponding values in the vanilla ruleset entry for power suit. If you wish to have your mod declare a change to another mod's listing, you put the code in the same way and simply ensure that your mod has priority over the other mod in the mod list.
Code: [Select]
armors:
  - type: STR_SUPER_SOLDIER_UP
    spriteSheet: XCOM_0.PCK
    spriteInv: MAN_0M5
    stats:
      tu: 7
      stamina: 20
      health: 10
      bravery: 20
      reactions: 20
      firing: 20
      throwing: 20
      strength: 13
      melee: 10
      psiStrength: 20
  - type: STR_PSI_DEFENSE_ARMOR_UC
    spriteSheet: PsiArmor1.PCK
    spriteInv: MAN_6
    corpseBattle:
      - STR_CORPSE_SUIT_PSI1
    storeItem: STR_PSI_DEFENSE_ARMOR
    stats:
      psiStrength: 30
      psiSkill: -20
    frontArmor: 120
    sideArmor: 100
    rearArmor: 90
    underArmor: 80
    damageModifier:
      - 1.0
      - 1.0
      - 0.2
      - 1.0
      - 1.0
      - 1.0
      - 0.7
      - 1.0
      - 1.0
      - 0.0
    loftempsSet: [ 3 ]
    forcedTorso: 1
  - type: STR_POWER_SUIT_UC
    stats:
      tu: 10
      strength: 20



Here is the code to set the graphics for the armors. The file paths (example: Resources/ReaversArmors/PsiArmor1.png) declares the location of the graphic file to be used. It automatically starts in the main mod folder and you can put your artwork in there and only declare the filename, but most modders prefer to put it inside of the Resources folder. I have a subfolder inside the Resources folder called ReaversArmors, and the graphics for this armor are in there.

PsiArmor1.PCK is the spriteSheet graphic, MAN_6.SPK is the spriteInv graphic. The BIGOBS.PCK and FLOOROBS.PCK entries are for the corpse, which has its own entry in the items section. Note that the first two entries here have the number 0 before the file path. This is because the graphic is being put into its own separate file once the game compiles the mod for play. Inversely, the last two entries have a number set before the file path (both 296 in this case). This is because the game is compiling them along with many other images into one single BIGOBS.PCK file and another FLOOROBS.PCK file. This means you must list in the corpse entry in the items section that its bigObs is 296 and its floorObs is 296. It is not usually optional whether you have something use its own graphic or compile into a collage; it is determined by where the file is used.
Code: [Select]
extraSprites:
  - type: PsiArmor1.PCK
    width: 512
    height: 720
    subX: 32
    subY: 40
    files:
      0: Resources/ReaversArmors/PsiArmor1.png
  - type: MAN_6.SPK
    singleImage: true
    files:
      0: Resources/ReaversArmors/MAN_6.gif
  - type: BIGOBS.PCK
    files:
      296: Resources/ReaversArmors/bigobs_psi_armor1.gif
  - type: FLOOROB.PCK
    files:
      296: Resources/ReaversArmors/floorob_psi_armor1.gif


I will leave you to set up your own items, research, ufopedia, manufacture, and language entries. You should be able to find all of the references you need in the base ruleset. There may be more attributes you can set which aren't listed in the default ruleset. These all have default values, but you can check the ruleset reference to find out about them so you can add any that you want. There are also always lots of possible entries you can make using OXCE+ which aren't listed. There is no ruleset reference to list them all, but you can sample other mods to use as references. Dioxine's X-Pirates mod is said to use almost every OXCE+ function. You can alternatively seek out a smaller mod made specifically to add soldiers or armor, for instance, to have less text to sift through.
« Last Edit: April 06, 2018, 11:42:59 pm by The Reaver of Darkness »

Offline Vangrimar1

  • Colonel
  • ****
  • Posts: 143
    • View Profile
Re: Algorithm for creating soldiers
« Reply #7 on: April 08, 2018, 05:57:04 am »
Thank you so much The Reaver of Darkness! Much has become clear. :)

Offline Vangrimar1

  • Colonel
  • ****
  • Posts: 143
    • View Profile
Re: Algorithm for creating soldiers
« Reply #8 on: July 12, 2018, 05:25:34 pm »
I want to add such a monster as a soldier, but in tactical mode there is a problem with the motion display. Please explain how to do this?

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1510
    • View Profile
Re: Algorithm for creating soldiers
« Reply #9 on: July 12, 2018, 07:35:21 pm »
What problem are you having?

Offline Yankes

  • Commander
  • *****
  • Posts: 3210
    • View Profile
Re: Algorithm for creating soldiers
« Reply #10 on: July 12, 2018, 10:55:27 pm »
I want to add such a monster as a soldier, but in tactical mode there is a problem with the motion display. Please explain how to do this?
You mean constant animation? Then if you use OXCE+ you can create custom animations cycles, recently I made one for 40k mod.

Offline Vangrimar1

  • Colonel
  • ****
  • Posts: 143
    • View Profile
Re: Algorithm for creating soldiers
« Reply #11 on: July 13, 2018, 08:28:01 am »
The problem with animation is solved, but there was another: when trying to fly, an error occurs.  "Invlid surface set "Demon.PCK" for armor: not enough frames.

--- posts merged; please don't bait the Holy Inquisition ---

The problem is completely eliminated, the reason was my inattention.
Regarding the constant animation, it would be very good for the demon to move its wings, but my knowledge is not enough to do this.
« Last Edit: July 13, 2018, 08:20:10 pm by Solarius Scorch »

Offline Yankes

  • Commander
  • *****
  • Posts: 3210
    • View Profile
Re: Algorithm for creating soldiers
« Reply #12 on: July 13, 2018, 04:12:04 pm »
Look at https://openxcom.org/forum/index.php/topic,6303.0.html
It easy to change to allow animation only when demon is in air