2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
4 * Copyright (c) 1999-2021 The Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
11 * The authors can be reached via e-mail at <crossfire@metalforge.org>.
27 with open(sys.argv[1],
'r')
as file:
29 start_type_list = re.compile(
r"enum object_type")
30 type_listing_match = re.compile(
r"^\W*(\w+)\s*\=\s*(\d+)\,?.*$")
31 end_type_list = re.compile(
r"^(([^}]*};).*)$")
33 start_handling =
False
34 line = file.readline()
36 while line
is not None:
38 if not start_handling:
39 found = start_type_list.search(line)
44 found = end_type_list.search(line)
47 found = type_listing_match.search(line)
50 if found.group(1) ==
"OBJECT_TYPE_MAX":
51 max_obj =
int(found.group(2))
54 type[
int(found.group(2))] =
True
55 line = file.readline()
58 print(
"/*****************************************")
59 print(
" * This file is automatically generated! *")
60 print(
" * Its contents will be overwritten on *")
61 print(
" * the next build. *")
63 print(
" * is_valid_types_gen.py generates this. *")
64 print(
" *****************************************/")
66 print(
" * Checks if the specified type is a valid one for a Crossfire object.")
68 print(
" * @param type value to check.")
69 print(
" * @return 1 if the type is valid, 0 else.")
71 print(
"#include <global.h>")
72 print(
"#include <libproto.h>")
73 print(
"int is_type_valid(uint8_t type) {")
74 print(
" if (type >= OBJECT_TYPE_MAX)")
76 print(
" switch (type) { // Listed types are invalid ones")
78 for i
in range(1, max_obj):
80 print(
" case %d:" % i)