summaryrefslogtreecommitdiffstats
path: root/tools/SectorTable/SectorTable.cpp
blob: 41cd895e01733b49e7e9a2dca66a64a33e6dc102 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// SectorTable.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <tlentity.hpp>

int _tmain(int argc, _TCHAR* argv[])
{
    const int NameCount = 75;
    char* sectorNames[ NameCount ] = {
        "l1r1.p3d", "l1r2.p3d", "l1r3.p3d", "l1r4a.p3d", "l1r4b.p3d", "l1r6.p3d", "l1r7.p3d",
        "l1z1.p3d", "l1z2.p3d", "l1z3.p3d", "l1z4.p3d", "l1z6.p3d", "l1z7.p3d",
        "l2r1.p3d", "l2r2.p3d", "l2r3.p3d", "l2r4.p3d",
        "l2z1.p3d", "l2z2.p3d", "l2z3.p3d", "l2z4.p3d",
        "l3r1.p3d", "l3r2.p3d", "l3r3.p3d", "l3r4.p3d", "l3r5.p3d",
        "l3z1.p3d", "l3z2.p3d", "l3z3.p3d", "l3z4.p3d", "l3z5.p3d",
        "l4r1.p3d", "l4r2.p3d", "l4r3.p3d", "l4r4a.p3d", "l4r4b.p3d", "l4r6.p3d", "l4r7.p3d",
        "l4z1.p3d", "l4z2.p3d", "l4z3.p3d", "l4z4.p3d", "l4z6.p3d", "l4z7.p3d",
        "l5r1.p3d", "l5r2.p3d", "l5r3.p3d", "l5r4.p3d",
        "l5z1.p3d", "l5z2.p3d", "l5z3.p3d", "l5z4.p3d",
        "l6r1.p3d", "l6r2.p3d", "l6r3.p3d", "l6r4.p3d", "l6r5.p3d",
        "l6z1.p3d", "l6z2.p3d", "l6z3.p3d", "l6z4.p3d", "l6z5.p3d",
        "l7r1.p3d", "l7r2.p3d", "l7r3.p3d", "l7r4a.p3d", "l7r4b.p3d", "l7r6.p3d", "l7r7.p3d",
        "l7z1.p3d", "l7z2.p3d", "l7z3.p3d", "l7z4.p3d", "l7z6.p3d", "l7z7.p3d" };

    char* typeStr[ 4 ] = { "unsigned char", "unsigned short", "int", "TLUID" };
    TLUID sectorIDs[ NameCount ];
    for( int i = 0; i < NameCount; ++i )
    {
        sectorIDs[ i ] = tlEntity::MakeUID( sectorNames[ i ] );
    }

    // Check for dups in the lower order bits.
    bool noDups = true;
    int type = 0;
    int mask = 0xFF;
    for( int i = 0; ( i < NameCount - 1 ) && ( noDups ); ++i )
    {
        char first = (char)( sectorIDs[ i ] & mask );
        for( int j = i + 1; j < NameCount; ++j )
        {
            char second = (char)( sectorIDs[ j ] & mask );
            if( first == second )
            {
                noDups = false;
                break;
            }
        }
    }
    if( !noDups )
    {
        ++type;
        noDups = true;
        mask = 0xFFFF;
        for( int i = 0; ( i < NameCount - 1 ) && ( noDups ); ++i )
        {
            short first = (short)( sectorIDs[ i ] & mask );
            for( int j = i + 1; j < NameCount; ++j )
            {
                short second = (short)( sectorIDs[ j ] & mask );
                if( first == second )
                {
                    noDups = false;
                    break;
                }
            }
        }
    }
    if( !noDups )
    {
        ++type;
        noDups = true;
        mask = 0xFFFFFFFF;
        for( int i = 0; ( i < NameCount - 1 ) && ( noDups ); ++i )
        {
            int first = (int)( sectorIDs[ i ] & mask );
            for( int j = i + 1; j < NameCount; ++j )
            {
                int second = (int)( sectorIDs[ j ] & mask );
                if( first == second )
                {
                    noDups = false;
                    break;
                }
            }
        }
    }
    if( !noDups )
    {
        ++type;
    }

    printf( "// Auto generated with SectorTable.\n" );
    printf( "struct SectorMap\n{\n    %s Sector;\n    char CurIndex;\n};\n\n", typeStr[ type ] );
    printf( "static const int NUM_SECTORS = %d;\n\n", NameCount );
    printf( "SectorMap sSectorMap[ NUM_SECTORS ] = {\n" );
    for( int i = 0; i < NameCount; ++i )
    {
        TLUID id = tlEntity::MakeUID( sectorNames[ i ] );
        unsigned hi = (unsigned)( id >> 32 );
        unsigned lo = (unsigned)( id & 0xFFFFFFFF );
        printf( "{ 0x" );
        switch( type )
        {
        case 0:
            printf("%02X", lo & 0xFF );
            break;
        case 1:
            printf("%04X", lo & 0xFFFF );
            break;
        case 2:
            printf("%08X", lo );
            break;
        default:
            printf( "%08X%08X", hi, lo );
            break;
        }
        printf( ", 0 }%s  //%s\n", i != NameCount -1 ? ",  " : " };", sectorNames[ i ] );
    }
	return 0;
}