d2mercs.c 12.7 KB
#include "d2mercs.h"

#include <stdio.h>
#include <stdlib.h>

D2Merc getMerc(D2CharHeader* c) {
    D2Merc mercData;
    switch(c->mercenaryType){
        case 0:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 1:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_COLD_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 2:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 3:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_COLD_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 4:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 5:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_COLD_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 6:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_COMBAT;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 7:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_DEFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 8:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_OFFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 9:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_COMBAT;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 10:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_DEFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 11:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_OFFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 12:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_COMBAT;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 13:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_DEFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 14:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_OFFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 15:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 16:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_COLD;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 17:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_LIGHTNING;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 18:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 19:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_COLD;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 20:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_LIGHTNING;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 21:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 22:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_COLD;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 23:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_LIGHTNING;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 24:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 25:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 26:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 27:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 28:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        default:
            mercData.type = D2S_MERCTYPE_UNKNOWN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_UNKNOWN;
        break;
    }
    if(mercData.type == D2S_MERCTYPE_UNKNOWN) {
        fprintf(stderr,"libd2char error: Unable to retrieve name for mercID %d, mercNameID %d\n",c->mercenaryType, c->mercenaryNameID);
        return mercData;
    }
    mercData.name = mercNames[c->mercenaryNameID + mercData.type];
    return mercData;
}

int setMerc(D2CharHeader* c, D2Merc* mercData) {
    switch(mercData->type) {
        case D2S_MERCTYPE_ROGUE:
            switch(mercData->subtype) {
                case D2S_MERCSUBTYPE_FIRE_ARROW:
                    switch(mercData->difficulty) {
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 0;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 2;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 4;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_COLD_ARROW:
                    switch(mercData->difficulty) {
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 1;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 3;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 5;
                            return 0;
                        break;
                    }
                break;
            }
        break;
        case D2S_MERCTYPE_DESERT:
            switch(mercData->subtype) {
                case D2S_MERCSUBTYPE_COMBAT:
                    switch(mercData->difficulty) {
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 6;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 9;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 12;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_DEFENSIVE:
                    switch(mercData->difficulty) {
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 7;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 10;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 13;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_OFFENSIVE:
                    switch(mercData->difficulty) {
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 8;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 11;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 14;
                            return 0;
                        break;
                    }
                break;
            }
        break;
        case D2S_MERCTYPE_SORCEROR:
            switch(mercData->subtype) {
                case D2S_MERCSUBTYPE_FIRE:
                    switch(mercData->difficulty) {
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 15;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 18;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 21;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_COLD:
                    switch(mercData->difficulty) {
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 16;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 19;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 22;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_LIGHTNING:
                    switch(mercData->difficulty) {
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 17;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 20;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 23;
                            return 0;
                        break;
                    }
                break;
            }
        break;
        case D2S_MERCTYPE_BARBARIAN:
            // There's actually 2 identifiers for barbarians in each difficulty, they don't seem to have 
            // noticeable effect in game, so I'm considering only one of them. If you want to specifcially
            // change to the other type, you probably know already what the mercID is so change it directly
            // in the header instead of using this function
            switch(mercData->difficulty) {
                case D2S_DIFFICULTY_NORMAL:
                    c->mercenaryType = 24;
                    return 0;
                break;
                case D2S_DIFFICULTY_NIGHTMARE:
                    c->mercenaryType = 26;
                    return 0;
                break;
                case D2S_DIFFICULTY_HELL:
                    c->mercenaryType = 28;
                    return 0;
                break;
            }
        break;
    }
    fprintf(stderr,"libd2char error: invalid combination of parameters for setMerc()\n");
    return -1;
}