1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Christian Meyer |
---|
13 | co-programmer: Benjamin Grauer |
---|
14 | */ |
---|
15 | |
---|
16 | |
---|
17 | #include "factory.h" |
---|
18 | |
---|
19 | #include "shell_command.h" |
---|
20 | #include "game_loader.h" |
---|
21 | using namespace std; |
---|
22 | |
---|
23 | /* -------------------------------------------------- |
---|
24 | * Factory |
---|
25 | * -------------------------------------------------- |
---|
26 | */ |
---|
27 | |
---|
28 | /** |
---|
29 | * constructor |
---|
30 | |
---|
31 | set everything to zero and define factoryName |
---|
32 | */ |
---|
33 | Factory::Factory (const char* factoryName) |
---|
34 | { |
---|
35 | this->setClassID(CL_FACTORY, "Factory"); |
---|
36 | this->setName(factoryName); |
---|
37 | |
---|
38 | this->next = NULL; |
---|
39 | |
---|
40 | Factory::registerFactory(this); |
---|
41 | } |
---|
42 | |
---|
43 | /** a reference to the First Factory */ |
---|
44 | Factory* Factory::first = NULL; |
---|
45 | |
---|
46 | /** |
---|
47 | * destructor |
---|
48 | |
---|
49 | clear the Q |
---|
50 | */ |
---|
51 | Factory::~Factory () |
---|
52 | { |
---|
53 | // printf("%s\n", this->factoryName); |
---|
54 | // Factory* tmpDel = this->next; |
---|
55 | // this->next = NULL; |
---|
56 | if (this->next) |
---|
57 | delete this->next; |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * add a Factory to the Factory Queue |
---|
62 | * @param factory a Factory to be registered |
---|
63 | */ |
---|
64 | void Factory::registerFactory( Factory* factory) |
---|
65 | { |
---|
66 | assert( factory != NULL); |
---|
67 | |
---|
68 | PRINTF(4)("Registered factory for '%s'\n", factory->getName()); |
---|
69 | |
---|
70 | if( Factory::first == NULL) |
---|
71 | { |
---|
72 | Factory::first = factory; |
---|
73 | ShellCommand<Factory>::registerCommand("create", CL_FACTORY, &Factory::fabricate); |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | Factory* tmpFac = Factory::first; |
---|
78 | while( tmpFac->next != NULL) |
---|
79 | { |
---|
80 | tmpFac = tmpFac->next; |
---|
81 | } |
---|
82 | tmpFac->setNext(factory); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | void Factory::fabricate(const char* className, const char* entityName) |
---|
87 | { |
---|
88 | if (className == NULL) |
---|
89 | return; |
---|
90 | Factory* fac = Factory::first; |
---|
91 | |
---|
92 | while (fac != NULL) |
---|
93 | { |
---|
94 | if (!strcmp(className, fac->getName())) |
---|
95 | { |
---|
96 | PRINTF(3)("Create a new Object of type %s\n", fac->getName()); |
---|
97 | BaseObject* object = fac->fabricateDirect(); |
---|
98 | if (object != NULL) |
---|
99 | { |
---|
100 | object->setName(entityName); |
---|
101 | } |
---|
102 | break; |
---|
103 | } |
---|
104 | fac = fac->next; |
---|
105 | } |
---|
106 | } |
---|