aboutsummaryrefslogtreecommitdiff
path: root/tools/worldgen.c
blob: 2c9a3bd66fb0b1b2e23c2705f0b8018dcb70408b (plain)
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
122
123
124
125
126
/* generates a 3d world with no content */

#include <globals.h>
#include <hash.h>
#include <room.h>

/* x and y are horizontal and forward-back axes, respectively */
/* z is the vertical axis */

#define MAX_X 100
#define MAX_Y 100
#define MAX_Z 1

struct direction_info_t {
    enum direction_t dir;
    int off_x, off_y, off_z;
} dirs[] = {
    { DIR_N,  0,  1,   0  },
    { DIR_NE, 1,  1,   0  },
    { DIR_E,  1,  0,   0  },
    { DIR_SE, 1,  -1,  0  },
    { DIR_S,  0,  -1,  0  },
    { DIR_SW, -1, -1,  0  },
    { DIR_W,  -1,  0,  0  },
    { DIR_NW, -1,  1,  0  },
    { DIR_UP, 0,   0,  1  },
    { DIR_DN, 0,   0,  -1 },
};

int main()
{
    printf("#include <world_api.h>\n");
    printf("const struct roomdata_t netcosm_world[] = {\n");

    for(int x = 0; x < MAX_X; ++x)
        for(int y = 0; y < MAX_Y; ++y)
            for(int z = 0; z < MAX_Z; ++z)
            {
                printf("{\n");
                printf("\"room_%d_%d_%d\",\n", x, y, z);
                printf("\"Room (%d,%d,%d)\",\n", x, y, z);
                printf("\"You are in a room...\",");

                char *adj[ARRAYLEN(dirs)];
                for(int i = 0; i < ARRAYLEN(dirs); ++i)
                {
                    int new_x = x + dirs[i].off_x,
                        new_y = y + dirs[i].off_y,
                        new_z = z + dirs[i].off_z;

                    if(new_x < 0 || new_x >= MAX_X ||
                       new_y < 0 || new_y >= MAX_Y ||
                       new_z < 0 || new_z >= MAX_Z)
                        asprintf(adj + i, "NULL");
                    else
                        asprintf(adj + i, "\"room_%d_%d_%d\"",
                                 new_x,
                                 new_y,
                                 new_z);
                }

                printf("{ ");
                for(int i = 0; i < ARRAYLEN(dirs); ++i)
                {
                    printf("%s, ", adj[i]);
                    free(adj[i]);
                }
                printf("NONE_IN, NONE_OT },\n");

                for(int i = 0; i < 6; ++i)
                    printf("NULL,\n");

                printf("},\n");
            }

    printf("};\n");
    printf("const size_t netcosm_world_sz = ARRAYLEN(netcosm_world);\n");
    printf("const char *netcosm_world_name = \"World Name Here\";\n");

    printf("static void generic_ser(int fd, struct object_t *obj)\n");
    printf("{\n");
    printf("    write_string(fd, obj->userdata);\n");
    printf("}\n");

    printf("static void generic_deser(int fd, struct object_t *obj)\n");
    printf("{\n");
    printf("    obj->userdata = read_string(fd);\n");
    printf("}\n");

    printf("static void generic_destroy(struct object_t *obj)\n");
    printf("{\n");
    printf("    free(obj->userdata);\n");
    printf("}\n");

    printf("static const char *generic_desc(struct object_t *obj, user_t *user)\n");
    printf("{\n");
    printf("    (void) user;\n");
    printf("    return obj->userdata;\n");
    printf("}\n");

    printf("static void *generic_dup(struct object_t *obj)\n");
    printf("{\n");
    printf("    return strdup(obj->userdata);\n");
    printf("}\n");

    printf("const struct obj_class_t netcosm_obj_classes[] = {\n");
    printf("    {\n");
    printf("        \"/generic\",\n");
    printf("        generic_ser,\n");
    printf("        generic_deser,\n");
    printf("        NULL,\n");
    printf("        NULL,\n");
    printf("        generic_destroy,\n");
    printf("        generic_desc,\n");
    printf("        generic_dup,\n");
    printf("    },\n");
    printf("};\n");
    printf("const size_t netcosm_obj_classes_sz = ARRAYLEN(netcosm_obj_classes);\n");

    printf("const struct verb_class_t netcosm_verb_classes[] = {\n");
    printf("\n");
    printf("};\n");
    printf("\n");
    printf("const size_t netcosm_verb_classes_sz = ARRAYLEN(netcosm_verb_classes);\n");

};