v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Editing 40d:Item quality

Jump to navigation Jump to search

Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.

You are editing a page for an older version of Dwarf Fortress ("Main" is the current version, not "40d"). Please make sure you intend to do this. If you are here by mistake, see the current page instead.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 119: Line 119:
  
 
:::::::::''Full code breakdown here:''
 
:::::::::''Full code breakdown here:''
{{Spoil small|Here is Quietust's disassembly and analysis, up-to-date as of version 0.28.181.40d:<br /><br />
+
{{Spoil small|Here is 0x517A5D's dis-assembly and analysis, up-to-date as of version .40d9:<br /><br />
  
 
---------------------------------------------------------------------------------
 
---------------------------------------------------------------------------------
 
<nowiki>
 
<nowiki>
; First, check what skill is being used
+
loc_6FCB92:
                                        ; arg_4 is the job being completed
 
                mov    ebx, [esp+44h+arg_4]
 
                                        ; arg_0 is the unit performing the job
 
                mov    esi, [esp+44h+arg_0]
 
                push    1
 
                mov    ebp, ecx        ; ECX is the item being created
 
                call    job_getSkill
 
                cmp    eax, 0FFFFFFFFh
 
                jnz    short loc_6EA4EC
 
                xor    edi, edi
 
                jmp    short loc_6EA4F4
 
 
 
; Next, get the level of that skill, if there is one (if not, it will use 0 instead)
 
loc_6EA4EC:
 
 
                 push    eax
 
                 push    eax
                 call    unit_getSkillLevel
+
                 call    get_dorf_level_in_a_skill
                 mov    edi, eax       ; Get the maker's uncapped skill level for the job
+
                 mov    ebx, eax
  
; Cap the skill level to a maximum of 20
+
loc_6FCB9A:
loc_6EA4F4:
+
                 cmp    ebx, 20
                 cmp    edi, 20
+
                 mov    [edi+7Ah], bx  ; Save the creator's true skill level.
                 mov    [ebp+60h], edi
+
                                        ; EDI points to the item being created.
                jle    short loc_6EA501
 
                mov    edi, 20
 
  
; Check if the item's type/subtype match any Item preferences in the maker
+
                 jle     short loc_6FCBA8
loc_6EA501:
+
                 mov    ebx, 20        ; EBX is a value in the range of [0..20],
                 mov     eax, [ebp+0]
+
                                        ; and is the (capped) skill level of the
                mov    edx, [eax+4]
+
                                        ; creator, possibly adjusted for material
                push    1
+
                                        ; preferences, I didn't check.
                push    0FFFFFFFFh
 
                push    0FFFFFFFFh
 
                 mov    ecx, ebp
 
                call    edx            ; get the item subtype
 
                mov    ecx, ebp
 
                push    eax
 
                mov    eax, [ebp+0]
 
                mov    edx, [eax]
 
                call    edx            ; and the item type
 
                push    eax
 
                push    4              ; LikeItem
 
                call    unit_checkPreference
 
                test    al, al
 
                jz      short loc_6EA52A
 
                add    edi, 1          ; if so, increase skill level by 1
 
 
 
; Check if the item's material/matgloss match any Material preferences in the maker
 
loc_6EA52A:
 
                movzx  eax, word ptr [ebp+58h]
 
                cmp    ax, 0FFFFh      ; skip if item has no material
 
                jz      short loc_6EA54E
 
                movzx  ecx, word ptr [ebp+5Ah]
 
                push    1
 
                push    ecx            ;field 5Ah is matgloss
 
                push    eax            ;field 58h is material
 
                push    0FFFFFFFFh
 
                push    0FFFFFFFFh
 
                push    0              ; LikeMaterial
 
                call    unit_checkPreference
 
                test    al, al
 
                jz      short loc_6EA54E
 
                add    edi, 1          ; if so, increase skill level by 1
 
  
 
; We roll a d5 and compare the result with the creator's skill level.
 
; We roll a d5 and compare the result with the creator's skill level.
 
; (Technically, we compare d5 - 1 against skill_level - 1.)
 
; (Technically, we compare d5 - 1 against skill_level - 1.)
  
loc_6EA54E:                            ; field 5Eh is quality
+
loc_6FCBA8:                            ; field 78h is quality.
                 mov    word ptr [ebp+5Eh], 0
+
                xor    eax, eax
 +
 
 +
                 mov    [edi+78h], ax  ; Init item quality to 0
  
                 call    mt_trandom      ; Get a random number (returned in EAX)
+
                 call    mt_engine      ; Get a random number (returned in EAX).
  
 
                 mov    ecx, eax        ; This mess is a division by 5,
 
                 mov    ecx, eax        ; This mess is a division by 5,
Line 210: Line 164:
 
                                         ; i.e. d5 - 1
 
                                         ; i.e. d5 - 1
  
                 cmp    edx, edi       ; Compare the "die roll" against the
+
                 cmp    edx, ebx       ; Compare the "die roll" against the
                                         ; 0-based skill level (still in EDI)
+
                                         ; 0-based skill level (still in EBX).
                 jge    short loc_6EA588
+
                 jge    short loc_6FCBE1
                                        ; If the random number was less than
+
                add    [edi+78h], bp  ; If the random number was less than
 
                                         ; the skill level,
 
                                         ; the skill level,
                add    word ptr [ebp+5Eh], 1
+
                                         ; add 1 to the quality level.
                                         ; add 1 to the quality level
+
                                        ; (BP is known to be 1, and
 +
                                        ; item quality is known to be 0.)
  
 
; Now we roll a d10 and compare.  It's important to note that the roll
 
; Now we roll a d10 and compare.  It's important to note that the roll
 
; of the d10 is independent, not conditional, of the roll of the d5.
 
; of the d10 is independent, not conditional, of the roll of the d5.
  
loc_6EA588:                            ; Random number
+
loc_6FCBE1:                            ; Random number
                 call    mt_trandom
+
                 call    mt_engine
 
                 mov    ecx, eax        ; Modulus
 
                 mov    ecx, eax        ; Modulus
 
                 mov    eax, 3
 
                 mov    eax, 3
Line 237: Line 192:
 
                 shr    edx, 1Ah        ; now EDX is in the range [0..9]
 
                 shr    edx, 1Ah        ; now EDX is in the range [0..9]
 
                                         ; i.e. d10 - 1
 
                                         ; i.e. d10 - 1
                 cmp    edx, edi       ; Compare
+
                 cmp    edx, ebx       ; Compare
                 jge    short loc_6EA5BC
+
                 jge    short loc_6FCC14
                                        ; If d10 < skill, bump quality
+
                add    [edi+78h], bp  ; If d10 < skill, bump quality.
                add    word ptr [ebp+5Eh], 1
 
  
loc_6EA5BC:                            ; Same thing for a d15
+
loc_6FCC14:                            ; Same thing for a d15.
                 call    mt_trandom
+
                 call    mt_engine
 
                 mov    ecx, eax
 
                 mov    ecx, eax
 
                 mov    eax, 3
 
                 mov    eax, 3
Line 258: Line 212:
 
                 shr    edx, 1Bh
 
                 shr    edx, 1Bh
 
                 cmp    edx, ebx
 
                 cmp    edx, ebx
                 jge    short loc_6EA5F0
+
                 jge    short loc_6FCC47
                                        ; If d15 < skill, bump quality
+
                add    [edi+78h], bp  ; If d15 < skill, bump quality.
                add    word ptr [ebp+5Eh], 1
 
  
loc_6EA5F0:                            ; Same thing for a d20
+
loc_6FCC47:                            ; Same thing for a d20.
                 call    mt_trandom
+
                 call    mt_engine
 
                 mov    ecx, eax
 
                 mov    ecx, eax
 
                 mov    eax, 3
 
                 mov    eax, 3
Line 280: Line 233:
 
                 add    ecx, edx
 
                 add    ecx, edx
 
                 shr    ecx, 1Ah
 
                 shr    ecx, 1Ah
                 cmp    ecx, edi
+
                 cmp    ecx, ebx
                 jge    short loc_6EA62A
+
                 jge    short loc_6FCC80
                                        ; If d20 < skill, bump quality
+
                add    [edi+78h], bp  ; If d20 < skill. bump quality.
                add    word ptr [ebp+5Eh], 1
 
  
loc_6EA62A:                            ; Now we roll a d25
+
loc_6FCC80:                            ; Now we roll a d25
                 call    mt_trandom
+
                 call    mt_engine
 
                 mov    ecx, eax
 
                 mov    ecx, eax
 
                 mov    eax, 3
 
                 mov    eax, 3
Line 300: Line 252:
 
                 mul    ecx
 
                 mul    ecx
 
                 shr    edx, 1Ah
 
                 shr    edx, 1Ah
                 cmp    edx, edi       ; Compare against skill,
+
                 cmp    edx, ebx       ; Compare against skill,
                 jge    short loc_6EA68B
+
                 jge    short loc_6FCCE2
                 call    mt_trandom      ; AND roll a d3
+
                 call    mt_engine      ; AND roll a d3
 
                 mov    ecx, eax
 
                 mov    ecx, eax
 
                 mov    eax, 3
 
                 mov    eax, 3
Line 316: Line 268:
 
                 mul    ecx
 
                 mul    ecx
 
                 shr    edx, 1Dh
 
                 shr    edx, 1Dh
                                        ; The d3 result must be 1.
+
                test    edx, edx        ; The d3 result must be 1.
 
                                         ; (Technically, d3-1 is tested against 0.)
 
                                         ; (Technically, d3-1 is tested against 0.)
                 jnz    short loc_6EA68B
+
                 jnz    short loc_6FCCE2
                                        ; If d25 < skill AND d3 = 1, bump
+
                add    [edi+78h], bp  ; If d25 < skill AND d3 = 1, bump
                add    word ptr [ebp+5Eh], 1
 
  
loc_6EA68B:
+
loc_6FCCE2:
                 cmp    word ptr [ebp+5Eh], 5
+
                 cmp    word ptr [edi+78h], 5
                 jnz    loc_6EA7BB
+
                 jnz    loc_6FCE28
                 xor     edi, edi
+
                 lea     ecx, [esp+40h+var_2C]
                mov    [esp+44h+var_14], 0Fh
+
                 call    ds:??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ
                 mov    [esp+44h+var_18], edi
+
                 lea     ecx, [esp-14h+arg_24]
                 mov     byte ptr [esp+44h+var_28], 0
+
                 push    ecx
                 push    esi
+
                 mov     ecx, esi
                 lea     ecx, [esp+48h+var_2C]
+
                 mov    [esp-10h+arg_4C], 0
                 mov    [esp+48h+__$EHRec$.state], edi
+
                 call    get_dorf_name
                 call    formatLanguageName
 
 
                 add    esp, 4
 
                 add    esp, 4
                push    1Bh
+
                 push    offset aHasCreatedAMasterpiece ; " has created a masterpiece!"
                 push    offset aHasCreatedAMas ; " has created a masterpiece!"
+
                 lea    ecx, [esp-10h+arg_24]
                 lea    eax, [esp+4Ch+var_2C]
+
                 call    ds:??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z
                 call    ??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z
+
                 cmp    [esp-18h+arg_40], 10h
                 ...
+
                mov    ecx, [esp-18h+arg_2C]
 +
                jnb    short loc_6FCD2C
 +
                lea    ecx, [esp-18h+arg_2C]
 
</nowiki>
 
</nowiki>
 
}}
 
}}

Please note that all contributions to Dwarf Fortress Wiki are considered to be released under the GFDL & MIT (see Dwarf Fortress Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)