Conflicts:
	src/sound/sound.h
dev-ui
erihel 2012-08-09 20:20:47 +02:00
commit 611680a72e
236 changed files with 32411 additions and 23225 deletions

View File

@ -5,16 +5,29 @@ cmake_minimum_required(VERSION 2.8)
project(colobot C CXX)
# Required packages
find_package(OpenGL REQUIRED)
find_package(SDL REQUIRED)
find_package(SDL_image REQUIRED)
find_package(OpenGL 1.4 REQUIRED)
find_package(SDL 1.2.10 REQUIRED)
find_package(SDL_image 1.2 REQUIRED)
find_package(PNG 1.2 REQUIRED)
# GLEW requirement depends on platform
# By default it is auto detected
# This setting may be used to override
# Possible values:
# - auto -> determine automatically
# - 1 -> always enable
# - 0 -> always disable
set(USE_GLEW auto)
# Build with debugging symbols
set(CMAKE_BUILD_TYPE debug)
# Global compile flags
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_DEBUG "-w -g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -Wold-style-cast -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wold-style-cast -std=gnu++0x")
# Include cmake directory
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${colobot_SOURCE_DIR}/cmake")
# Subdirectory with sources
add_subdirectory(src bin)

View File

@ -690,8 +690,7 @@ INPUT_ENCODING = UTF-8
# *.f90 *.f *.for *.vhd *.vhdl
FILE_PATTERNS = *.h \
*.cpp \
*.doc.txt
*.cpp
# The RECURSIVE tag can be used to turn specify whether or not subdirectories
# should be searched for input files as well. Possible values are YES and NO.

133
HOWTO.txt
View File

@ -1,77 +1,104 @@
EN
How to...
1. Compile the game with MinGW.
1. Compile the game.
1. Download and install DirectX 8.1 SDK. It can be difficult to find it now as it is old SDK, but here is a working dowload link:
http://dl.dropbox.com/u/32866936/dx81sdk_full.exe
2. Download and install MinGW and MSYS:
1.1 Windows:
1. Download and install MinGW and MSYS:
http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20111118/
When installing, select all available components.
3. Download and install CMake:
2. Download and install CMake:
http://www.cmake.org/cmake/resources/software.html (the Windows zip file)
Unpack the contents of the archive to where MinGW is installed (files from bin/ should go into bin/, etc.)
4. In the file src/CMakeLists.txt, change "set(DXSDK_DIR "c:/dxsdk") to the directory, where you have DirectX SDK
(the slashes must be in this form: /, not \).
5. Run MinGW console from the shortcut in menu start.
6. Change to the directory where you have the Colobot sources by typing "cd /c/where/the/sources/are"
7. Type "cmake -G 'MSYS Makefiles' ."
8. Type "make"
9. Everything should compile without errors.
3. Download the following libraries, installing them in your MinGW directory like with CMake:
SDL >=1.2.10, SDL_imgage >= 1.2, SDL_ttf >= 2.0, libpng >= 1.2, GLEW >= 1.8.0
Note #1: For most libraries, you can download binary packages with compiled files.
However, you must ensure that they work with MinGW as some are built with MSVC
and may be incompatible. If that is the case, you should compile the libraries from sources
using MinGW.
Note #2: For GLEW, you need to compile from source under MinGW. Since there is no automated
make script for that, follow the instructions here: http://stackoverflow.com/questions/6005076/
4. Run MinGW console from the shortcut in menu start.
5. Change to the directory where you have the Colobot sources by typing "cd /c/where/the/sources/are"
6. Type "cmake -G 'MSYS Makefiles' ."
7. Type "make"
8. Everything should compile without errors.
1.2 Linux:
Since you're running Linux, you probably know how to do this anyway ;)
But just in case, here's what you need:
gcc compiler (with gcc-g++), cmake, libraries with header files: SDL, SDL_image, SDL_ttf, libpng
Instructions are the same:
$ cmake .
$ make
Note: If you experience problems with OpenGL's extensions, install GLEW library and enable
it in compilation by setting USE_GLEW to 1 in CMakeLists.txt
1.3 Other platforms, compilers, etc.
We haven't checked other platforms yet but the code isn't particularly tied to any compiler or platform, so in theory it should work.
If you can, please try to compile the code on your platform and let us know how it goes.
2. Run the compiled game.
1. Download and unpack the package with the game data files.
2. Copy the compiled files from bin/colobot.exe, bin/CBot/libCBot.dll
and from the directory, where MinGW is installed bin/libgcc_s_dw2-1.dll and bin/libstdc++-6.dll
to the directory with game data (there should be several files named colobot*.dat).
3. Create a shortcut to the colobot.exe executable and add to the executed command " -nocd" option.
4. Run the shortcut and enjoy the game.
3. But it's in French! How to change the language?
1. In the source code, find language.h file and change the line #define FRENCH TRUE to #define FRENCH FALSE and do the reverse
on on the language of your choice (English, German or Polish).
2. Recompile the game and copy bin/colobot.exe.
3. In the directory with game data switch the directories scene, script and help with those from the directory of given language
(e.g. english/).
4. Run the game.
1. Download development data package - make sure you get the latest version as the files will be changed/moved around.
Currently the files are hosted at: http://colobot.info/files (packages are named colobot-data-YYYY-MM-DD.zip)
2. Unpack the data package to any place you want.
3. Run the game with commandline option "-datadir where_you_put_the_data_dir" and enjoy the game.
PL
Jak...
1. Skompilować projekt pod MinGW.
1. Skompilować grę.
1. Ściągamy i instalujemy DirectX SDK w wersji 8.1. Może być problem ze znalezieniem linka bo to już stary SDK, ale można ściągnąć stąd:
http://dl.dropbox.com/u/32866936/dx81sdk_full.exe
2. Ściągamy i instalujemy MinGW i MSYS:
1.1 Windows:
1. Ściągamy i instalujemy MinGW i MSYS:
http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20111118/
Przy instalacji zaznaczamy wszystkie komponenty do instalacji.
3. Ściągamy i instalujemy CMake:
2. Ściągamy i instalujemy CMake:
http://www.cmake.org/cmake/resources/software.html (plik zip dla Windowsa)
Zip rozpakowujemy do katalogu, gdzie zainstalowany jest MinGW (pliki z bin/ mają trafić do bin/ itd.).
4. W pliku src/CMakeLists.txt zmieniamy set(DXSDK_DIR "c:/dxsdk") na katalog, gdzie jest zainstalowany DirectX SDK (w wersji 8.1)
(slashe mają być właśnie w takiej postaci: / a nie \).
5. Uruchamiamy MinGW console ze skrótu w menu start.
6. Przechodzimy do katalogu, gdzie są źródła wpisując "cd /c/tam/gdzie/sa/zrodla"
7. Wpisujemy "cmake -G 'MSYS Makefiles' ."
8. Wpisujemy "make"
9. Wszystko powinno się skomplikować bez błędów.
3. Ścągamy następujące biblioteki i instalujemy je tam, gdzie MinGW, podobnie jak z CMake:
SDL >= 1.2.10, SDL_image >= 1.2, SDL_ttf >= 2.0, libpng >= 1.2
Uwaga #1: W większości wymienionych bibliotek można ściągnąć paczki binarne ze skompilowanymi plikami.
Jednak musisz się upewnić, że pliki te będą współpracowały z MinGW, bo część z nich
jest kompilowana MSVC i może być niezgodna. W takim wypadku, musisz skompilować bibliotekę
ze źródeł pod MinGW.
Uwaga #2: W przypadku GLEW, musisz skompilować bibiotekę ze źródeł pod MinGW. Ponieważ nie ma skryptu
make do tego, użyj poleceń opisanych tutaj: http://stackoverflow.com/questions/6005076/
4. Uruchamiamy MinGW console ze skrótu w menu start.
5. Przechodzimy do katalogu, gdzie są źródła wpisując "cd /c/tam/gdzie/sa/zrodla"
6. Wpisujemy "cmake -G 'MSYS Makefiles' ."
7. Wpisujemy "make"
8. Wszystko powinno się skomplikować bez błędów.
1.2 Linux:
Skoro już masz Linuksa, to prawdpobodobnie wiesz co robić ;)
Ale na wszelki wypadek, potrzebujesz tego:
kompilator gcc (razem z gcc-g++), cmake, biblioteki wraz z nagłówkami: SDL, SDL_image, SDL_ttf, libpng
Polecenia są takie same:
$ cmake .
$ make
Uwaga: Jeśli natrafisz na problemy z rozszerzeniami OpenGL, zainstaluj bibliotekę GLEW i włącz ją
przy kompilacji, ustawiając USE_GLEW na 1 w CMakeLists.txt
1.3 Inne platformy, kompilatory, etc.
Nie sprawdzaliśmy jeszcze innych platform, ale kod nie jest jakoś specjalnie związany z danym kompilatorem czy platformą, więc w teorii powinien zadziałać.
Jeśli możesz, spróbuj skompilować kod na twojej platformie i daj nam znać jak poszło.
2. Uruchomić skompilowaną grę.
1. Ściągamy paczkę z plikami danych gry.
2. Kopiujemy skompilowane pliki bin/colobot.exe, bin/CBot/libCBot.dll
i z katalogu, gdzie jest zainstalowany MinGW bin/libgcc_s_dw2-1.dll i bin/libstdc++-6.dll
do katalogu z plikami danych (powinno być tam kilka plików colobot*.dat).
3. Tworzymy skrót do colobot.exe, przy czym w wywoływanej komendzie dopisujemy na końcu opcję " -nocd".
4. Odpalamy skrót i cieszymy się grą.
3. Ale gra jest po francusku! Jak zmienić język?
1. W kodzie źródłowym znajdujemy plik language.h i zmieniamy #define FRENCH TRUE na #define FRENCH FALSE i robimy odwrotnie
dla wybranego języka (angielski, niemiecki lub polski).
2. Kompilujemy od nowa grę i kopiujemy bin/colobot.exe.
3. W katalogu z plikami danych podmieniamy katalogi scene, script i help z tymi z katalogu danego języka (np. english/).
4. Odpalamy grę.
1. Ściągamy paczkę developerską z plikami danych gry - upewnij się, że jest to najnowsza wersja, bo pliki będą zmieniane/przenoszone.
2. Wypakowujemy pliki gdziekolwiek.
3. Uruchamiamy grę wraz z opcją "-datadir tam_gdzie_rozpakowałeś_paczkę" i cieszymy się grą.

674
LICENSE.txt Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -1,4 +1,4 @@
README for Developers
Please refer to our wiki for developers for current information. Its current address is:
http://colobot.info/wiki/doku.php?id=developers
http://colobot.info/wiki/

View File

@ -1,14 +1,30 @@
EN
Welcome to Colobot project repository
This repository contains the source files of Colobot game released on open source license (GNU GPLv3) by the producer Epsitec CH. The sources were released and the rights granted to a group of Polish Colobot fans centered around the site http://colobot.cba.pl/ . This repository contains only the source code of the game. The necessary data files will soon be available as a separate download. For now, though, you can download the original download package released by Epsitec (the link is on http://colobot.cba.pl/ site).
This is official repository for the open-source Colobot project developed by Polish Portal of Colobot (PPC; Polish: Polski Portal Colobota) with the official site at: http://colobot.cba.pl/.
The source code contained here was released by Epsitec -- the original creator of the game -- on open source (GPLv3) license. The code was given and the rights granted specifically to PPC community in March 2012. Since then, we have been modifying the code and working on our goals, which are briefly summed up below. More information about the project in general will soon appear on our site and a wiki we are writing.
This repository contains only the source code of the game. The game requires also data files which will soon be made available in separate packages. For now, though, you can download the original download package released by Epsitec (the link is on our site).
For more information on the project, see the wiki pages.
Status
Our first goal has been reached now: the project has been successfully ported to CMake build system and MinGW compiler from the original MSVC6 project.
Our main goals can be summed up in three milestones:
Milestone 1 - Colobot Classic
This is a version of the game that is comprised of the original source files with only minor changes and bugfixes. It is currently maintained in branch named "original" and the master branch is synced to it to provide a working version of the project. There will soon be download packages for the game, in several language versions.
Milestone 2 - Colobot Gold
This is a version of the game that we are now focusing our efforts on. It will be the original, refreshed game rewritten using SDL and OpenGL libraries, thus making it multiplatform. Development for this version is continued in dev branch and sub-branches dev-*. The data files will not be altered and the game will be as close to the original as possible. With this release, we hope to reach wider audience and gain more support.
Milestone 3 - Colobot 2
This will be a new installment in the Colobot series. We have many ideas for the new game and we are still discussing them. Generally, the development of this version will begin only after finishing Colobot Gold (it will be probably hosted in another repository, forked off the Colobot Gold code).
Now our goal is to port the game to OpenGL and SDL, thus making it multiplatform. Further goals include adding new features to the game, though that will be decided later on.
Compiling and running the game
@ -16,4 +32,38 @@ For these instructions see HOWTO.txt file.
Contact
If you want to help in the project, please contact us on the forum on our website (there is also an English board).
If you want to help in the project, please contact us on our IRC channel #colobot at pirc.pl or the forum on our website: http://colobot.cba.pl/forum (there is also an English board).
PL
Witamy w repozytorium projektu Colobot
To jest oficjalne repozytorium z kodem projektu open-source Colobot rozwijanego przez Polski Portal Colobota (PPC; angielski: Polish Portal of Colobot) z oficjalną stroną: http://colobot.cba.pl/.
Kod źródłowy zawarty tutaj został wydany przez Epsitec -- oryginalnego twórcę gry -- na otwartej licencji (GPLv3). Kod został wydany i prawa nadane specjalnie dla społeczności PPC w marcu 2012. Od tamtej pory, zajmujemy się modyfikowaniem kodu i pracowaniem nad naszymi celami, które są krótko podsumowane poniżej. Więcej informacji o projekcie w ogóle pojawi się wkrótce na naszej stronie i na wiki, które w tej chwili piszemy.
To repozytorium zawiera tylko kod źródłowy gry. Gra wymaga też plików danych, które niedługo zostaną przygotowane w osobnej paczce. Na razie, możesz pobrać oryginalną paczkę wydaną przez Epsitec (link znajduje się na naszej stronie).
Status
Nasze główne cele można podsumować w trzech krokach, które chcemy osiągnąć:
Krok 1 - Colobot Classic
To jest wersja gry, która składa się z oryginalnych źródeł, z jedynie niewielkimi zmianami i poprawkami. Obecnie znajduje się w gałęzi nazwanej "original", a gałąź master jest z nią zsynchronizowana, aby udostępnić działającą wersję projektu. Niedługo pojawią się paczki do pobrania gry w kilku wersjach językowych.
Krok 2 - Colobot Gold
To jest wersja gry, na której obecnie się skupiamy. Jest to oryginalna, odświeżona gra, przepisana z użyciem bibliotek SDL i OpenGL, w ten sposób czyniąc ją wieloplatformową. Rozwój tej wersji kontynuujemy w gałęzi dev i podgałęziach dev-*. Pliki danych nie będą zmienione dla tej wersji i gra będzie na tyle zbliżona do oryginału na ile to możliwe. Z tym wydaniem, chcemy dotrzeć do szerszej społeczności i uzyskać większe poparcie.
Krok 3 - Colobot 2
To będzie nowa część z cyklu gier Colobot. Mamy wiele pomysłów na nową grę i nadal dyskutujemy nad nimi. Ogólnie, rozwój tej wersji zacznie się po skończeniu wersji Colobot Gold (prawdopodobnie będzie hostowane w osobnym repozytorium, sforkowanym z kodu Colobot Gold).
Kompilacja i uruchomienie gry
Instrukcje te znajdują się w pliku HOWTO.txt.
Kontakt
Jeżeli chcesz pomóc w projekcie, prosimy o kontakt na naszym kanale IRC: #colobot na pirc.pl albo na forum na naszej stronie: http://colobot.cba.pl/forum.

51
cmake/FindGLEW.cmake Normal file
View File

@ -0,0 +1,51 @@
# CMake module to find GLEW
# Borrowed from http://code.google.com/p/nvidia-texture-tools/
# MIT license Copyright (c) 2007 NVIDIA Corporation
# Try to find GLEW library and include path.
# Once done this will define
#
# GLEW_FOUND
# GLEW_INCLUDE_PATH
# GLEW_LIBRARY
#
IF (WIN32)
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
$ENV{PROGRAMFILES}/GLEW/include
${PROJECT_SOURCE_DIR}/src/nvgl/glew/include
DOC "The directory where GL/glew.h resides")
FIND_LIBRARY( GLEW_LIBRARY
NAMES glew GLEW glew32 glew32s
PATHS
/mingw/bin # for MinGW's MSYS
/mingw/lib
${PROJECT_SOURCE_DIR}/glew/bin # or in local directory
${PROJECT_SOURCE_DIR}/glew/lib
DOC "The GLEW library")
ELSE (WIN32)
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
/usr/include
/usr/local/include
/sw/include
/opt/local/include
DOC "The directory where GL/glew.h resides")
FIND_LIBRARY( GLEW_LIBRARY
NAMES GLEW glew
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
DOC "The GLEW library")
ENDIF (WIN32)
IF (GLEW_INCLUDE_PATH)
SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
ELSE (GLEW_INCLUDE_PATH)
SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
ENDIF (GLEW_INCLUDE_PATH)
MARK_AS_ADVANCED( GLEW_FOUND )

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,279 +0,0 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// French (France) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
#ifdef _WIN32
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE DISCARDABLE
BEGIN
ID_IF "if"
ID_ELSE "else"
ID_WHILE "while"
ID_DO "do"
ID_FOR "for"
ID_BREAK "break"
ID_CONTINUE "continue"
ID_SWITCH "switch"
ID_CASE "case"
ID_DEFAULT "default"
ID_TRY "try"
ID_THROW "throw"
ID_CATCH "catch"
ID_FINALLY "finally"
ID_TXT_AND "and"
ID_TXT_OR "or"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_DEBUGDD "STARTDEBUGDD"
ID_INT "int"
ID_FLOAT "float"
ID_BOOLEAN "boolean"
ID_STRING "string"
ID_VOID "void"
ID_BOOL "bool"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_TXT_NOT "not"
ID_RETURN "return"
ID_CLASS "class"
ID_EXTENDS "extends"
ID_SYNCHO "synchronized"
ID_NEW "new"
ID_PUBLIC "public"
ID_EXTERN "extern"
ID_FINAL "final"
ID_STATIC "static"
ID_PROTECTED "protected"
ID_PRIVATE "private"
ID_REPEAT "repeat"
END
STRINGTABLE DISCARDABLE
BEGIN
TX_OPENPAR "Il manque une parenthèse ouvrante."
TX_CLOSEPAR "Il manque une parenthèse fermante."
TX_NOTBOOL "L'expression doit être un boolean."
TX_UNDEFVAR "Variable non déclarée."
TX_BADLEFT "Assignation impossible."
TX_ENDOF "Terminateur point-virgule non trouvé."
TX_OUTCASE "Instruction ""case"" hors d'un bloc ""switch""."
TX_NOTERM "Instructions après la fin."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_CLOSEBLK "Il manque la fin du bloc."
TX_ELSEWITHOUTIF "Instruction ""else"" sans ""if"" correspondant."
TX_OPENBLK "Début d'un bloc attendu."
TX_BADTYPE "Mauvais type de résultat pour l'assignation."
TX_REDEFVAR "Redéfinition d'une variable."
TX_BAD2TYPE "Les deux opérandes ne sont pas de types compatibles."
TX_UNDEFCALL "Routine inconnue."
TX_MISDOTS "Séparateur "" : "" attendu."
TX_WHILE "Manque le mot ""while""."
TX_BREAK "Instruction ""break"" en dehors d'une boucle."
TX_LABEL "Un label ne peut se placer que devant un ""for"", un ""while"" ou un ""do""."
TX_NOLABEL "Cette étiquette n'existe pas"
TX_NOCASE "Manque une instruction ""case""."
TX_BADNUM "Un nombre est attendu."
TX_VOID "Paramètre void."
TX_NOTYP "Déclaration de type attendu."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_DIVZERO "Division par zéro."
TX_NOTINIT "Variable non initialisée."
TX_BADTHROW "Valeur négative refusée pour ""throw""."
TX_NORETVAL "La fonction n'a pas retourné de résultat"
TX_NORUN "Pas de fonction en exécution"
TX_NOCALL "Appel d'une fonction inexistante"
TX_NOCLASS "Cette classe n'existe pas"
TX_NULLPT "Pointeur nul."
TX_OPNAN "Opération sur un ""nan"""
TX_OUTARRAY "Accès hors du tableau"
TX_STACKOVER "Dépassement de la pile"
TX_DELETEDPT "Pointeur à un objet détruit"
TX_FILEOPEN "Ouverture du fichier impossible"
TX_NOTOPEN "Fichier pas ouvert"
TX_ERRREAD "Erreur de lecture"
TX_ERRWRITE "Erreur d'écriture"
END
STRINGTABLE DISCARDABLE
BEGIN
TX_NOVAR "Nom d'une variable attendu."
TX_NOFONC "Nom de la fonction attendu."
TX_OVERPARAM "Trop de paramètres."
TX_REDEF "Cette fonction existe déjà."
TX_LOWPARAM "Pas assez de paramètres."
TX_BADPARAM "Aucune fonction de ce nom n'accepte ce(s) type(s) de paramètre(s)."
TX_NUMPARAM "Aucune fonction de ce nom n'accepte ce nombre de paramètres."
TX_NOITEM "Cet élément n'existe pas dans cette classe."
TX_DOT "L'objet n'est pas une instance d'une classe."
TX_NOCONST "Il n'y a pas de constructeur approprié."
TX_REDEFCLASS "Cette classe existe déjà."
TX_CLBRK """ ] "" attendu."
TX_RESERVED "Ce mot est réservé."
TX_BADNEW "Mauvais argument pour ""new""."
TX_OPBRK """ [ "" attendu."
TX_BADSTRING "Une chaîne de caractère est attendue."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_BADINDEX "Mauvais type d'index"
TX_PRIVATE "Membre privé de la classe"
TX_NOPUBLIC """public"" manque"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_OPENPAR "("
ID_CLOSEPAR ")"
ID_OPBLK "{"
ID_CLBLK "}"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_SEP ";"
ID_COMMA ","
ID_DOTS ":"
ID_DOT "."
ID_OPBRK "["
ID_CLBRK "]"
ID_DBLDOTS "::"
ID_LOGIC "?"
ID_ADD "+"
ID_SUB "-"
ID_MUL "*"
ID_DIV "/"
ID_ASS "="
ID_ASSADD "+="
ID_ASSSUB "-="
ID_ASSMUL "*="
END
STRINGTABLE DISCARDABLE
BEGIN
ID_TRUE "true"
ID_FALSE "false"
ID_NULL "null"
ID_NAN "nan"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_ASSDIV "/="
ID_ASSOR "|="
ID_ASSAND "&="
ID_ASSXOR "^="
ID_ASSSL "<<="
ID_ASSSR ">>>="
ID_ASSASR ">>="
ID_SL "<<"
ID_SR ">>>"
ID_ASR ">>"
ID_INC "++"
ID_DEC "--"
ID_LO "<"
ID_HI ">"
ID_LS "<="
ID_HS ">="
END
STRINGTABLE DISCARDABLE
BEGIN
ID_EQ "=="
ID_NE "!="
ID_AND "&"
ID_XOR "^"
ID_OR "|"
ID_LOG_AND "&&"
ID_LOG_OR "||"
ID_LOG_NOT "!"
ID_NOT "~"
ID_MODULO "%"
ID_POWER "**"
ID_ASSMODULO "%="
END
STRINGTABLE DISCARDABLE
BEGIN
TX_UNDEF "undefined"
TX_NAN "not a number"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_SUPER "super"
END
#endif // French (France) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -1,142 +1,144 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
// expression du genre Opérande1 + Opérande2
// Opérande1 - Opérande2
#include "CBot.h"
// divers constructeurs
CBotAddExpr::CBotAddExpr()
{
m_leftop =
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
name = "CBotAddExpr"; // debug
}
CBotAddExpr::~CBotAddExpr()
{
delete m_leftop;
delete m_rightop;
}
// compile une instruction de type A + B
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
{
CBotStack* pStk = pStack->TokenStack(); // un bout de pile svp
// cherche des instructions qui peuvent convenir à gauche de l'opération + ou -
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B à gauche
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
// est-ce qu'on a le token + ou - ensuite ?
if ( p->GetType() == ID_ADD ||
p->GetType() == ID_SUB) // plus ou moins
{
CBotAddExpr* inst = new CBotAddExpr(); // élément pour opération
inst->SetToken(p); // mémorise l'opération
int type1, type2;
type1 = pStack->GetType(); // de quel type le premier opérande ?
p = p->Next(); // saute le token de l'opération
// cherche des instructions qui peuvent convenir à droite
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) à droite
{
// il y a un second opérande acceptable
type2 = pStack->GetType(); // de quel type le résultat ?
if ( type1 == type2 ) // les résultats sont-ils compatibles
{
// si ok, enregistre l'opérande dans l'objet
inst->m_leftop = left;
// et rend l'object à qui l'a demandé
return pStack->Return(inst, pStk);
}
}
// en cas d'erreur, libère les éléments
delete left;
delete inst;
// et transmet l'erreur qui se trouve sur la pile
return pStack->Return(NULL, pStk);
}
// si on n'a pas affaire à une opération + ou -
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
// à la place de l'objet "addition"
return pStack->Return(left, pStk);
}
// fait l'opération d'addition ou de soustraction
BOOL CBotAddExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
// if ( pSk1 == EOX ) return TRUE;
// selon la reprise, on peut être dans l'un des 2 états
if ( pStk1->GetState() == 0 && // 1er état, évalue l'opérande de gauche
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
// passe à l'étape suivante
pStk1->SetState(1); // prêt pour la suite
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
// qui se trouve sur la pile, justement.
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
// 2e état, évalue l'opérande de droite
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
int type1 = pStk1->GetType(); // de quels types les résultats ?
int type2 = pStk2->GetType();
// crée une variable temporaire pour y mettre le résultat
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
// fait l'opération selon la demande
switch (GetTokenType())
{
case ID_ADD:
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
break;
case ID_SUB:
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
break;
}
pStk2->SetVar(result); // met le résultat sur la pile
pStk1->Return(pStk2); // libère la pile
return pStack->Return(pStk1); // transmet le résultat
}
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
///////////////////////////////////////////////////
// expressions of type Operand1 + Operand2
// Operand1 - Operand2
#include "CBot.h"
// various constructors
CBotAddExpr::CBotAddExpr()
{
m_leftop =
m_rightop = NULL; // NULL to be able to delete without further
name = "CBotAddExpr"; // debug
}
CBotAddExpr::~CBotAddExpr()
{
delete m_leftop;
delete m_rightop;
}
// compile une instruction de type A + B
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
{
CBotStack* pStk = pStack->TokenStack(); // one end of stack please
// looking statements that may be suitable to the left of the operation + or -
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B left
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
// do we have the token + or - next?
if ( p->GetType() == ID_ADD ||
p->GetType() == ID_SUB) // more or less
{
CBotAddExpr* inst = new CBotAddExpr(); // element for operation
inst->SetToken(p); // stores the operation
int type1, type2;
type1 = pStack->GetType(); // what kind of the first operand?
p = p->Next(); // skip the token of the operation
// looking statements that may be suitable for right
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) rigth
{
// there is an acceptable second operand
type2 = pStack->GetType(); // what kind of results?
if ( type1 == type2 ) // are the results consistent ?
{
// ok so, saves the operand in the object
inst->m_leftop = left;
// and makes the object on demand
return pStack->Return(inst, pStk);
}
}
// in case of error, free the elements
delete left;
delete inst;
// and transmits the error that is on the stack
return pStack->Return(NULL, pStk);
}
// if we are not dealing with an operation + or -
// goes to that requested, the operand (left) found
// place the object "addition"
return pStack->Return(left, pStk);
}
// operation is addition or subtraction
bool CBotAddExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or is found in case of recovery
// if ( pSk1 == EOX ) return TRUE;
// according to recovery, it may be in one of two states
if ( pStk1->GetState() == 0 && // first state, evaluates the left operand
!m_leftop->Execute(pStk1) ) return FALSE; // interrupted here?
// passes to the next step
pStk1->SetState(1); // ready for further
// requires a little more stack to not touch the result of the left
// which is on the stack, precisely.
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// or is found in case of recovery
// Second state, evaluates the right operand
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here?
int type1 = pStk1->GetType(); // what kind of results?
int type2 = pStk2->GetType();
// creates a temporary variable to put the result
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
// is the operation as requested
switch (GetTokenType())
{
case ID_ADD:
result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition
break;
case ID_SUB:
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction
break;
}
pStk2->SetVar(result); // puts the result on the stack
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmits the result
}

File diff suppressed because it is too large Load Diff

View File

@ -1,131 +1,133 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
// expression du genre Opérande1 > Opérande2
// Opérande1 != Opérande2
// etc.
#include "CBot.h"
// divers constructeurs
CBotCompExpr::CBotCompExpr()
{
m_leftop =
m_rightop = NULL;
name = "CBotCompExpr";
}
CBotCompExpr::~CBotCompExpr()
{
delete m_leftop;
delete m_rightop;
}
fichier plus utilise;
// compile une instruction de type A < B
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotCStack* pStk = pStack->AddStack();
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B à gauche
if (left == NULL) return pStack->Return(NULL, pStk); // erreur
if ( p->GetType() == ID_HI ||
p->GetType() == ID_LO ||
p->GetType() == ID_HS ||
p->GetType() == ID_LS ||
p->GetType() == ID_EQ ||
p->GetType() == ID_NE) // les diverses comparaisons
{
CBotCompExpr* inst = new CBotCompExpr(); // élément pour opération
inst->SetToken(p); // mémorise l'opération
int type1, type2;
type1 = pStack->GetType();
p = p->Next();
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B à droite
{
type2 = pStack->GetType();
// les résultats sont-ils compatibles
if ( type1 == type2 )
{
inst->m_leftop = left;
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
// le résultat est un boolean
return pStack->Return(inst, pStk);
}
}
delete left;
delete inst;
return pStack->Return(NULL, pStk);
}
return pStack->Return(left, pStk);
}
// fait l'opération
BOOL CBotCompExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this);
// if ( pStk1 == EOX ) return TRUE;
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
pStk1->SetState(1); // opération terminée
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
CBotStack* pStk2 = pStk1->AddStack();
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
int type1 = pStk1->GetType();
int type2 = pStk2->GetType();
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
switch (GetTokenType())
{
case ID_LO:
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // inférieur
break;
case ID_HI:
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // supérieur
break;
case ID_LS:
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // inférieur ou égal
break;
case ID_HS:
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // supérieur ou égal
break;
case ID_EQ:
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // égal
break;
case ID_NE:
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // différent
break;
}
pStk2->SetVar(result); // met le résultat sur la pile
pStk1->Return(pStk2); // libère la pile
return pStack->Return(pStk1); // transmet le résultat
}
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
///////////////////////////////////////////////////
// expression of type Opérande1 > Opérande2
// Opérande1 != Opérande2
// etc.
#include "CBot.h"
// various constructeurs
CBotCompExpr::CBotCompExpr()
{
m_leftop =
m_rightop = NULL;
name = "CBotCompExpr";
}
CBotCompExpr::~CBotCompExpr()
{
delete m_leftop;
delete m_rightop;
}
fichier plus utilise;
// compile instruction of type A < B
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotCStack* pStk = pStack->AddStack();
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B left
if (left == NULL) return pStack->Return(NULL, pStk); // error
if ( p->GetType() == ID_HI ||
p->GetType() == ID_LO ||
p->GetType() == ID_HS ||
p->GetType() == ID_LS ||
p->GetType() == ID_EQ ||
p->GetType() == ID_NE) // the various comparisons
{
CBotCompExpr* inst = new CBotCompExpr(); // element for operation
inst->SetToken(p); // stores the operation
int type1, type2;
type1 = pStack->GetType();
p = p->Next();
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B right
{
type2 = pStack->GetType();
// are the results compatible
if ( type1 == type2 )
{
inst->m_leftop = left;
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
// the result is a boolean
return pStack->Return(inst, pStk);
}
}
delete left;
delete inst;
return pStack->Return(NULL, pStk);
}
return pStack->Return(left, pStk);
}
// perform the operation
bool CBotCompExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this);
// if ( pStk1 == EOX ) return TRUE;
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here ?
pStk1->SetState(1); // finished
// requires a little more stack to not touch the result of the left
CBotStack* pStk2 = pStk1->AddStack();
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ?
int type1 = pStk1->GetType();
int type2 = pStk2->GetType();
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
switch (GetTokenType())
{
case ID_LO:
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower
break;
case ID_HI:
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher
break;
case ID_LS:
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal
break;
case ID_HS:
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal
break;
case ID_EQ:
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal
break;
case ID_NE:
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal
break;
}
pStk2->SetVar(result); // puts the result on the stack
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmit the result
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,159 +1,161 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////////////////////////
// instruction if (condition) opération1 else opération2;
#include "CBot.h"
// les divers constructeurs / destructeurs
CBotIf::CBotIf()
{
m_Condition =
m_Block =
m_BlockElse = NULL; // NULL pour pouvoir faire delete directement
name = "CBotIf"; // debug
}
CBotIf::~CBotIf()
{
delete m_Condition; // libère la condition
delete m_Block; // libère le bloc d'instruction1
delete m_BlockElse; // libère le bloc d'instruction2
}
// compilation (routine statique)
// appelé lorsque le token "if" a été trouvé
CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotToken* pp = p; // conserve le ^au token (début instruction)
if (!IsOfType(p, ID_IF)) return NULL; // ne doit jamais arriver
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
CBotIf* inst = new CBotIf(); // crée l'object
inst->SetToken( pp );
if ( NULL != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
{
// la condition existe bel et bien
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
if ( pStk->IsOk() )
{
// le bloc d'instruction est ok (peut être vide)
// regarde si l'instruction suivante est le token "else"
if (IsOfType(p, ID_ELSE))
{
// si oui, compile le bloc d'instruction qui suit
inst->m_BlockElse = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
if (!pStk->IsOk())
{
// il n'y a pas de bloc correct après le else
// libère l'objet, et transmet l'erreur qui est sur la pile
delete inst;
return pStack->Return(NULL, pStk);
}
}
// rend l'object correct à qui le demande.
return pStack->Return(inst, pStk);
}
}
// erreur, libère l'objet
delete inst;
// et transmet l'erreur qui se trouve sur la pile.
return pStack->Return(NULL, pStk);
}
// exécution de l'instruction
BOOL CBotIf :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
// if ( pile == EOX ) return TRUE;
if ( pile->IfStep() ) return FALSE;
// selon la reprise, on peut être dans l'un des 2 états
if( pile->GivState() == 0 )
{
// évalue la condition
if ( !m_Condition->Execute(pile) ) return FALSE; // interrompu ici ?
// termine s'il y a une erreur
if ( !pile->IsOk() )
{
return pj->Return(pile); // transmet le résultat et libère la pile
}
// passe dans le second état
if (!pile->SetState(1)) return FALSE; // prêt pour la suite
}
// second état, évalue les instructions associées
// le résultat de la condition est sur la pile
if ( pile->GivVal() == TRUE ) // condition était vraie ?
{
if ( m_Block != NULL && // bloc peut être absent
!m_Block->Execute(pile) ) return FALSE; // interrompu ici ?
}
else
{
if ( m_BlockElse != NULL && // s'il existe un bloc alternatif
!m_BlockElse->Execute(pile) ) return FALSE; // interrompu ici
}
// transmet le résultat et libère la pile
return pj->Return(pile);
}
void CBotIf :: RestoreState(CBotStack* &pj, BOOL bMain)
{
if ( !bMain ) return;
CBotStack* pile = pj->RestoreStack(this); // ajoute un élément à la pile
if ( pile == NULL ) return;
// selon la reprise, on peut être dans l'un des 2 états
if( pile->GivState() == 0 )
{
// évalue la condition
m_Condition->RestoreState(pile, bMain); // interrompu ici !
return;
}
// second état, évalue les instructions associées
// le résultat de la condition est sur la pile
if ( pile->GivVal() == TRUE ) // condition était vraie ?
{
if ( m_Block != NULL ) // bloc peut être absent
m_Block->RestoreState(pile, bMain); // interrompu ici !
}
else
{
if ( m_BlockElse != NULL ) // s'il existe un bloc alternatif
m_BlockElse->RestoreState(pile, bMain); // interrompu ici !
}
}
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
///////////////////////////////////////////////////////////////////////
// instruction if (condition) operation1 else operation2;
#include "CBot.h"
// various constructors / destructors
CBotIf::CBotIf()
{
m_Condition =
m_Block =
m_BlockElse = NULL; // NULL so that delete is not possible further
name = "CBotIf"; // debug
}
CBotIf::~CBotIf()
{
delete m_Condition; // frees the condition
delete m_Block; // frees the block of instruction1
delete m_BlockElse; // frees the block of instruction2
}
// compilation (static routine)
// called when the token "if" has been found
CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotToken* pp = p; // preserves at the ^ token (starting instruction)
if (!IsOfType(p, ID_IF)) return NULL; // should never happen
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
CBotIf* inst = new CBotIf(); // create the object
inst->SetToken( pp );
if ( NULL != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
{
// the condition does exist
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
if ( pStk->IsOk() )
{
// the statement block is ok (can be empty)
// see if the next instruction is the token "else"
if (IsOfType(p, ID_ELSE))
{
// if so, compiles the following statement block
inst->m_BlockElse = CBotBlock::CompileBlkOrInst( p, pStk, true );
if (!pStk->IsOk())
{
// there is no correct block after the else
// frees the object, and transmits the error that is on the stack
delete inst;
return pStack->Return(NULL, pStk);
}
}
// return the corrent object to the application
return pStack->Return(inst, pStk);
}
}
// error, frees the object
delete inst;
// and transmits the error that is on the stack.
return pStack->Return(NULL, pStk);
}
// execution of the instruction
bool CBotIf :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); // adds an item to the stack
// or found in case of recovery
// if ( pile == EOX ) return true;
if ( pile->IfStep() ) return false;
// according to recovery, it may be in one of two states
if( pile->GivState() == 0 )
{
// evaluates the condition
if ( !m_Condition->Execute(pile) ) return false; // interrupted here?
// terminates if there is an error
if ( !pile->IsOk() )
{
return pj->Return(pile); // returns the results and releases the stack
}
// passes into the second state
if (!pile->SetState(1)) return false; // ready for further
}
// second state, evaluates the associated instructions
// the result of the condition is on the stack
if ( pile->GivVal() == true ) // condition was true?
{
if ( m_Block != NULL && // block may be absent
!m_Block->Execute(pile) ) return false; // interrupted here?
}
else
{
if ( m_BlockElse != NULL && // if there is an alternate block
!m_BlockElse->Execute(pile) ) return false; // interrupted here
}
// sends the results and releases the stack
return pj->Return(pile);
}
void CBotIf :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack
if ( pile == NULL ) return;
// according to recovery, it may be in one of two states
if( pile->GivState() == 0 )
{
// evaluates the condition
m_Condition->RestoreState(pile, bMain); // interrupted here!
return;
}
// second state, evaluates the associated instructions
// the result of the condition is on the stack
if ( pile->GivVal() == true ) // condition was true?
{
if ( m_Block != NULL ) // block may be absent
m_Block->RestoreState(pile, bMain); // interrupted here!
}
else
{
if ( m_BlockElse != NULL ) // if there is an alternate block
m_BlockElse->RestoreState(pile, bMain); // interrupted here!
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +1,38 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.////////////////////////////////////////////////////////////////////
// interpréteur pour le language CBot du jeu COLOBOT
// un programme écrit est tout d'abord transformé en une liste de tokens
// avant d'aborder le compilateur proprement dit
// par exemple
// int var = 3 * ( pos.y + x )
// est décomposé en (chaque ligne est un token)
// int
// var
// =
// 3
// *
// (
// pos.y
// +
// x
// )
extern BOOL IsOfType(CBotToken* &p, int type1, int type2 = -1);
extern BOOL IsOfTypeList(CBotToken* &p, int type1, ...);
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// interpreter of the lanuage CBot for game COLOBOT
// writing a program is first transformed into a list of tokens
// before tackling the compiler itself
// for example
// int var = 3 * ( pos.y + x )
// is decomposed into (each line is a token)
// int
// var
// =
// 3
// *
// (
// pos.y
// +
// x
// )
#pragma once
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,6 @@ CBotToken.cpp
CBotTwoOpExpr.cpp
CBotVar.cpp
CBotWhile.cpp
CBot.rc
)
add_library(CBot SHARED ${SOURCES})

View File

@ -1,426 +1,428 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.// ClassFile.cpp
//
// définition des méthodes pour la classe FILE
// Variables statiques
static CBotClass* m_pClassFILE;
static CBotProgram* m_pFuncFile;
static int m_CompteurFileOpen = 0;
// Prépare un nom de fichier.
void PrepareFilename(CBotString &filename) //DD!
{
int pos;
pos = filename.ReverseFind('\\');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // enlève les dossiers
}
pos = filename.ReverseFind('/');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // aussi ceux avec /
}
pos = filename.ReverseFind(':');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // enlève aussi la lettre d'unité C:
}
filename = CBotString("files\\") + filename;
}
// constructeur de la classe
// reçois le nom du fichier en paramètre
// exécution
BOOL rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
CBotString mode;
// accepte sans paramètre
if ( pVar == NULL ) return TRUE;
// qui doit être une chaîne de caractères
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
// il peut y avoir un second paramètre
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// récupère le mode
mode = pVar->GivValString();
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
}
// enregistre le nom du fichier
pVar = pThis->GivItem("filename");
pVar->SetValString(filename);
if ( ! mode.IsEmpty() )
{
// ouvre le ficher demandé
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return FALSE; }
m_CompteurFileOpen ++;
// enregiste le canal du fichier
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
}
return TRUE;
}
// compilation
CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
{
// accepte sans paramètre
if ( pVar == NULL ) return CBotTypResult( 0 );
// qui doit être une chaine
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// il peut y avoir un second paramètre
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// qui doit être une chaine
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
}
// le résultat est de type void (constructeur)
return CBotTypResult( 0 );
}
// destructeur de la classe
// exécution
BOOL rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// récupère l'élément "handle"
pVar = pThis->GivItem("handle");
// pas ouvert ? pas de problème
if ( pVar->GivInit() != IS_DEF) return TRUE;
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
m_CompteurFileOpen --;
pVar->SetInit(IS_NAN);
return TRUE;
}
// méthode FILE :: open
// reçois le mode r/w en paramètre
// exécution
BOOL rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il doit y avoir un paramètre
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
// qui doit être une chaîne de caractères
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
// il peut y avoir un second paramètre
if ( pVar->GivNext() != NULL )
{
// dans ce cas le premier paramètre est le nom du fichier
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
// enregistre le nom du fichier
CBotVar* pVar2 = pThis->GivItem("filename");
pVar2->SetValString(filename);
// paramètre suivant est le mode
pVar = pVar -> GivNext();
}
CBotString mode = pVar->GivValString();
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
// récupère l'élément "handle"
pVar = pThis->GivItem("handle");
// qui doit pas être initialisé
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return FALSE; }
// reprend le nom du fichier
pVar = pThis->GivItem("filename");
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DD! (si le nom a été attribué par h.filename = "...";
// ouvre le ficher demandé
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) //DR
{
pResult->SetValInt(FALSE); //DR
return TRUE; //DR
}
m_CompteurFileOpen ++;
// enregiste le canal du fichier
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
pResult->SetValInt(TRUE); //DR
return TRUE;
}
// compilation
CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar)
{
// il doit y avoir un paramètre
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
// qui doit être une chaine
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// il peut y avoir un second paramètre
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// qui doit être une chaine
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
}
// le résultat est de type bool
return CBotTypResult(CBotTypBoolean); //DR
}
// méthode FILE :: close
// exécution
BOOL rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) return CBotErrOverParam;
// récupère l'élément "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
m_CompteurFileOpen --;
pVar->SetInit(IS_NAN);
return TRUE;
}
// compilation
CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// la fonction retourne un résultat "void"
return CBotTypResult( 0 );
}
// méthode FILE :: writeln
// exécution
BOOL rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il doit y avoir un paramètre
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
// qui doit être une chaîne de caractères
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
CBotString param = pVar->GivValString();
// récupère l'élément "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
FILE* pFile= (FILE*)pVar->GivValInt();
int res = fputs(param+CBotString("\n"), pFile);
// en cas d'erreur génère une exception
if ( res < 0 ) { Exception = CBotErrWrite; return FALSE; }
return TRUE;
}
// compilation
CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
{
// il doit y avoir un paramètre
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
// qui doit être une chaîne de caractères
if ( pVar->GivType() != CBotTypString ) return CBotTypResult( CBotErrBadString );
// pas d'autre paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
// la fonction retourne un résultat void
return CBotTypResult( 0 );
}
// méthode FILE :: readln
// exécution
BOOL rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
// récupère l'élément "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
FILE* pFile= (FILE*)pVar->GivValInt();
char chaine[2000];
int i;
for ( i = 0 ; i < 2000 ; i++ ) chaine[i] = 0;
fgets(chaine, 1999, pFile);
for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0;
// en cas d'erreur génère une exception
if ( ferror(pFile) ) { Exception = CBotErrRead; return FALSE; }
pResult->SetValString( chaine );
return TRUE;
}
// compilation
CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// la fonction retourne un résultat "string"
return CBotTypResult( CBotTypString );
}
// méthode FILE :: readln
// exécution
BOOL rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
// récupère l'élément "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
FILE* pFile= (FILE*)pVar->GivValInt();
pResult->SetValInt( feof( pFile ) );
return TRUE;
}
// compilation
CBotTypResult cfeof (CBotVar* pThis, CBotVar* &pVar)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// la fonction retourne un résultat booleen
return CBotTypResult( CBotTypBoolean );
}
void InitClassFILE()
{
// crée une classe pour la gestion des fichiers
// l'utilisation en est la suivante:
// file canal( "NomFichier.txt" )
// canal.open( "r" ); // ouvre en lecture
// s = canal.readln( ); // lit une ligne
// canal.close(); // referme le fichier
// crée la classe FILE
m_pClassFILE = new CBotClass("file", NULL);
// ajoute le composant ".filename"
m_pClassFILE->AddItem("filename", CBotTypString);
// ajoute le composant ".handle"
m_pClassFILE->AddItem("handle", CBotTypInt, PR_PRIVATE);
// défini un constructeur et un destructeur
m_pClassFILE->AddFunction("file", rfconstruct, cfconstruct );
m_pClassFILE->AddFunction("~file", rfdestruct, NULL );
// défini les méthodes associées
m_pClassFILE->AddFunction("open", rfopen, cfopen );
m_pClassFILE->AddFunction("close", rfclose, cfclose );
m_pClassFILE->AddFunction("writeln", rfwrite, cfwrite );
m_pClassFILE->AddFunction("readln", rfread, cfread );
m_pClassFILE->AddFunction("eof", rfeof, cfeof );
m_pFuncFile = new CBotProgram( );
CBotStringArray ListFonctions;
m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
m_pFuncFile->SetIdent(-2); // identificateur spécial pour RestoreState dans cette fonction
}
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// ClassFile.cpp
//
// definition of methods for class FILE
// Static variables
static CBotClass* m_pClassFILE;
static CBotProgram* m_pFuncFile;
static int m_CompteurFileOpen = 0;
// Prepares a file name.
void PrepareFilename(CBotString &filename) //DD!
{
int pos;
pos = filename.ReverseFind('\\');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // remove the records (files)??
}
pos = filename.ReverseFind('/');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // also those with /
}
pos = filename.ReverseFind(':');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // also removes the drive letter C:
}
filename = CBotString("files\\") + filename;
}
// constructor of the class
// gets the filename as a parameter
// execution
bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
CBotString mode;
// accepts no parameters
if ( pVar == NULL ) return true;
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// recovers the mode
mode = pVar->GivValString();
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
// no third parameter, only two or one possible
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
}
// save the file name
pVar = pThis->GivItem("filename");
pVar->SetValString(filename);
if ( ! mode.IsEmpty() )
{
// open the called file
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return false; }
m_CompteurFileOpen ++;
// save the handle of file
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
}
return true;
}
// compilation
CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
{
// accepts no parameters
if ( pVar == NULL ) return CBotTypResult( 0 );
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
}
// le r<>sultat est de type void (constructeur)
return CBotTypResult( 0 );
}
// destructor of the class
// execution
bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
// not open? no problem
if ( pVar->GivInit() != IS_DEF) return true;
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
m_CompteurFileOpen --;
pVar->SetInit(IS_NAN);
return true;
}
// FILE :: open method
// get the r / w mode as a parameter
// execution
bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there must be a parameter
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
// there may be a second parameter
if ( pVar->GivNext() != NULL )
{
// in this case the first parameter is the file name
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
// saves the file name
CBotVar* pVar2 = pThis->GivItem("filename");
pVar2->SetValString(filename);
// next parameter is the mode
pVar = pVar -> GivNext();
}
CBotString mode = pVar->GivValString();
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
// No third parameter
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
// which must not be initialized
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return false; }
// contains filename
pVar = pThis->GivItem("filename");
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DD! (if the name was assigned by h.filename = "...";
// open requsted file
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) //DR
{
pResult->SetValInt(false); //DR
return true; //DR
}
m_CompteurFileOpen ++;
// saves the handle of file
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
pResult->SetValInt(true); //DR
return true;
}
// compilation
CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar)
{
// there must be a parameter
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
}
// the result is of type bool
return CBotTypResult(CBotTypBoolean); //DR
}
// FILE :: close method
// execution
bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// it should not be any parameter
if ( pVar != NULL ) return CBotErrOverParam;
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
m_CompteurFileOpen --;
pVar->SetInit(IS_NAN);
return true;
}
// compilation
CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
{
// it should not be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function returns a result "void"
return CBotTypResult( 0 );
}
// FILE :: writeln method
// execution
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there must be a parameter
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
CBotString param = pVar->GivValString();
//retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
int res = fputs(param+CBotString("\n"), pFile);
// on error throws an exception
if ( res < 0 ) { Exception = CBotErrWrite; return false; }
return true;
}
// compilation
CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
{
// there must be a parameter
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
// must be a string
if ( pVar->GivType() != CBotTypString ) return CBotTypResult( CBotErrBadString );
// no other parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
// function returns "void" result
return CBotTypResult( 0 );
}
// FILE :: readln method
// execution
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there shouldn't be any parameter
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
//retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
char chaine[2000];
int i;
for ( i = 0 ; i < 2000 ; i++ ) chaine[i] = 0;
fgets(chaine, 1999, pFile);
for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0;
// on error throws an exception
if ( ferror(pFile) ) { Exception = CBotErrRead; return false; }
pResult->SetValString( chaine );
return true;
}
// compilation
CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
{
// there shouldn't be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function return "string" result
return CBotTypResult( CBotTypString );
}
// FILE :: readln method
// execution
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there shouldn't be any parameter
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
pResult->SetValInt( feof( pFile ) );
return true;
}
// compilation
CBotTypResult cfeof (CBotVar* pThis, CBotVar* &pVar)
{
// there shouldn't be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function return boolean result
return CBotTypResult( CBotTypBoolean );
}
void InitClassFILE()
{
// creates a class for file management
// the usage is as follows:
// file canal( "NomFichier.txt" )
// canal.open( "r" ); // open reading
// s = canal.readln( ); // reads a line
// canal.close(); // closes the file
// create class FILE
m_pClassFILE = new CBotClass("file", NULL);
// add the component ".filename"
m_pClassFILE->AddItem("filename", CBotTypString);
// add the component ".handle"
m_pClassFILE->AddItem("handle", CBotTypInt, PR_PRIVATE);
// define a constructor and destructor
m_pClassFILE->AddFunction("file", rfconstruct, cfconstruct );
m_pClassFILE->AddFunction("~file", rfdestruct, NULL );
// defined associated methods
m_pClassFILE->AddFunction("open", rfopen, cfopen );
m_pClassFILE->AddFunction("close", rfclose, cfclose );
m_pClassFILE->AddFunction("writeln", rfwrite, cfwrite );
m_pClassFILE->AddFunction("readln", rfread, cfread );
m_pClassFILE->AddFunction("eof", rfeof, cfeof );
m_pFuncFile = new CBotProgram( );
CBotStringArray ListFonctions;
m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
m_pFuncFile->SetIdent(-2); // restoreState as a special identifier for this function
}

View File

@ -1,434 +1,436 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.// définition des fonctions sur les chaînes
// donne la longueur d'une chaîne
// exécution
BOOL rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// pas de second paramètre
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// met la longueur sur la pile
pResult->SetValInt( s.GivLength() );
return TRUE;
}
// int xxx ( string )
// compilation
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADPARAM );
// pas de second paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est un nombre entier
return CBotTypResult( CBotTypInt );
}
// donne la partie gauche d'une chaîne
// exécution
BOOL rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// il faut un second paramètre
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être un nombre
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
// récupère ce nombre
int n = pVar->GivValInt();
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
// prend la partie intéressante
s = s.Left( n );
// la met sur la pile
pResult->SetValString( s );
return TRUE;
}
// string xxx ( string, int )
// compilation
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// il faut un second paramètre
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être un nombre
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est une string
return CBotTypResult( CBotTypString );
}
// donne la partie droite d'une chaîne
// exécution
BOOL rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// il faut un second paramètre
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être un nombre
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
// récupère ce nombre
int n = pVar->GivValInt();
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
// prend la partie intéressante
s = s.Right( n );
// la met sur la pile
pResult->SetValString( s );
return TRUE;
}
// donne la partie centrale d'une chaîne
// exécution
BOOL rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// il faut un second paramètre
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être un nombre
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
// récupère ce nombre
int n = pVar->GivValInt();
// 3e paramètre optionnel
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// qui doit être un nombre
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
// récupère ce nombre
int l = pVar->GivValInt();
// mais pas de 4e paramètre
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
// prend la partie intéressante
s = s.Mid( n, l );
}
else
{
// prend la partie intéressante
s = s.Mid( n );
}
// la met sur la pile
pResult->SetValString( s );
return TRUE;
}
// donne la partie centrale d'une chaîne
// compilation
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// il faut un second paramètre
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être un nombre
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// 3e paramètre optionnel
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// qui doit être un nombre
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// pas de 4e paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
}
// le résultat final est une string
return CBotTypResult( CBotTypString );
}
// donne le nombre contenu dans une chaîne
// exécution
BOOL rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// mais pas de 2e paramètre
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
float val = GivNumFloat(s);
// la met la valeur sur la pile
pResult->SetValFloat( val );
return TRUE;
}
// float xxx ( string )
// compilation
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// pas de 2e paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est un nombre
return CBotTypResult( CBotTypFloat );
}
// trouve une chaine dans une autre
// exécution
BOOL rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// il faut un second paramètre
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// récupère ce nombre
CBotString s2 = pVar->GivValString();
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
// met le résultat sur la pile
int res = s.Find(s2);
pResult->SetValInt( res );
if ( res < 0 ) pResult->SetInit( IS_NAN );
return TRUE;
}
// int xxx ( string, string )
// compilation
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// il faut un second paramètre
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// pas de 3e paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est un nombre
return CBotTypResult( CBotTypInt );
}
// donne une chaine en majuscule
// exécution
BOOL rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// mais pas de 2e paramètre
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
s.MakeUpper();
// la met la valeur sur la pile
pResult->SetValString( s );
return TRUE;
}
// donne une chaine en minuscules
// exécution
BOOL rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
// qui doit être une string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// mais pas de 2e paramètre
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
s.MakeLower();
// la met la valeur sur la pile
pResult->SetValString( s );
return TRUE;
}
// string xxx ( string )
// compilation
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// pas de 2e paramètre
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est une string
return CBotTypResult( CBotTypString );
}
void InitStringFunctions()
{
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
}
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// definition of string functions
// gives the length of a chain
// execution
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// no second parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// puts the length of the stack
pResult->SetValInt( s.GivLength() );
return true;
}
// int xxx ( string )
// compilation
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADPARAM );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is an integer
return CBotTypResult( CBotTypInt );
}
// gives the left side of a chain
// execution
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int n = pVar->GivValInt();
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// takes the interesting part
s = s.Left( n );
// puts on the stack
pResult->SetValString( s );
return true;
}
// string xxx ( string, int )
// compilation
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is a string
return CBotTypResult( CBotTypString );
}
// gives the right of a string
// execution
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int n = pVar->GivValInt();
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// takes the interesting part
s = s.Right( n );
// puts on the stack
pResult->SetValString( s );
return true;
}
// gives the central part of a chain
// execution
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int n = pVar->GivValInt();
// third parameter optional
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int l = pVar->GivValInt();
// but no fourth parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
// takes the interesting part
s = s.Mid( n, l );
}
else
{
// takes the interesting part
s = s.Mid( n );
}
// puts on the stack
pResult->SetValString( s );
return true;
}
// gives the central part of a chain
// compilation
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// third parameter optional
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// no fourth parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
}
// the end result is a string
return CBotTypResult( CBotTypString );
}
// gives the number stored in a string
// execution
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
float val = GivNumFloat(s);
// puts the value on the stack
pResult->SetValFloat( val );
return true;
}
// float xxx ( string )
// compilation
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is a number
return CBotTypResult( CBotTypFloat );
}
// find string in other
// exécution
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// retrieves this number
CBotString s2 = pVar->GivValString();
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// puts the result on the stack
int res = s.Find(s2);
pResult->SetValInt( res );
if ( res < 0 ) pResult->SetInit( IS_NAN );
return true;
}
// int xxx ( string, string )
// compilation
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is a number
return CBotTypResult( CBotTypInt );
}
// gives a string to uppercase
// exécution
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
s.MakeUpper();
// puts the value on the stack
pResult->SetValString( s );
return true;
}
// gives a string to lowercase
// exécution
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
s.MakeLower();
// puts the value on the stack
pResult->SetValString( s );
return true;
}
// string xxx ( string )
// compilation
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is a string
return CBotTypResult( CBotTypString );
}
void InitStringFunctions()
{
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
}

View File

@ -1,2 +0,0 @@
copy debug\cbot.dll "F:\Program Files\Ceebot\cbot.dll"
cls

View File

@ -1,49 +0,0 @@
[Directory]
scene=scene
savegame=savegame
public=program
user=user
[Setup]
TotoMode=1
Tooltips=1
InterfaceGlint=1
NiceMouse=0
Movies=1
NiceReset=1
HimselfDamage=1
CameraScroll=1
CameraInvertX=0
InterfaceEffect=1
GroundShadow=1
GroundSpot=1
ObjectDirty=1
FogMode=1
LensMode=1
SkyMode=1
PlanetMode=1
LightMode=1
UseJoystick=0
ParticuleDensity=1.00
ClippingDistance=1.00
ObjectDetail=2.00
GadgetQuantity=1.00
TextureQuality=1
AudioVolume=20
MidiVolume=15
Sound3D=0
EditIndentMode=1
EditIndentValue=4
KeyMap=37+0 39+0 38+0 40+0 16+0 17+0 32+258 96+262 13+257 107+261 109+260 9+259 36+263 27+0 112+0 113+0 110+0 115+0 116+0 117+0
[Engine]
AlphaMode=1
StateColor=-1
BlackSrcBlend=0
BlackDestBlend=0
WhiteSrcBlend=0
WhiteDestBlend=0
DiffuseSrcBlend=0
DiffuseDestBlend=0
AlphaSrcBlend=0
AlphaDestBlend=0
[Gamer]
LastName=Player

View File

@ -1,39 +1,41 @@
pour la gestion des instances d'une classe.
l'objet créé actuellement avec CBotVar::Create(nom, pClasse)
est a conserver tel quel, en dehors des vars sur la pile
for managing instances of a class.
il faut un autre type de variable pour garder les pointeurs
CBotTypPtClass par exemple
the object being created with CBotVar :: Create (name, pClasse)
is to keep as is, outside the vars on the stack
L'instance de la classe doit avoir un compteur d'utilisation
qui est le nombre d'objet de classe CBotTypPtClass qui y réfèrent.
Le compteur est décrémenté lorsque le pointeur est détruit,
l'objet supprimé lorsqu'il n'y a plus de pointeurs.
we need another type of variable to keep the pointers
For example CBotTypPtClass
The instance of the class must have a usage count
which is the number of class object to which they refer CBotTypPtClass.
The counter is decremented when the pointer is destroyed,
be deleted when there is more pointers.
Dans le cas des robots, Daniel crée une instance de sa classe "Object"
et peut retourner des pointeurs à cette instance par des routines genre FindRobot()
In the case of robots, Daniel creates an instance of class "Object"
and can return pointers to this proceeding by routines such FindRobot ()
Object FindRobot(int n) { }
Object FindRobot (int n) {}
pResult dans ce cas est un pointeur CBotTypPtClass
lorsqu'il a trouvé le robot concerné, il lui faudra faire
pResult in this case is a pointer CBotTypPtClass
when he found the robot concerned, it must make
pResult->SetPointeur(InstanceDeLaClassObject);
pResult-> SetPointeur (InstanceDeLaClassObject);
cette opération incrémente le compteur des références
this operation increments the reference
--
-
lorsque le robot est détruit, l'instance de la classe Object correspondant
est détruit également.
s'il reste des pointeurs à cet objet, et l'on risque la planté
when the robot is destroyed, the instance of the Object class corresponding
is also destroyed.
if there are pointers to that object, and we planted the risk
solution 1:
garder non pas le pointeur à l'objet directement, mais
un index dans une tables de pointeurs
Solution 1:
not keep the pointer to the object directly, but
an index into a table of pointers
Solution 2:
not destroy the object when there imédiatement pointers
but marked as virtually destroyed
solution 2:
ne pas détruire l'objet imédiatement lorsqu'il reste des pointeurs
mais le marqué comme virtuellement détruit

View File

@ -1,15 +0,0 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.

View File

@ -1,180 +1,177 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by CBot.rc
//
#define ID_KEYWORDS 2000
#define ID_IF 2000
#define ID_ELSE 2001
#define ID_WHILE 2002
#define ID_DO 2003
#define ID_FOR 2004
#define ID_BREAK 2005
#define ID_CONTINUE 2006
#define ID_SWITCH 2007
#define ID_CASE 2008
#define ID_DEFAULT 2009
#define ID_TRY 2010
#define ID_THROW 2011
#define ID_CATCH 2012
#define ID_FINALLY 2013
#define ID_TXT_AND 2014
#define ID_TXT_OR 2015
#define ID_TXT_NOT 2016
#define ID_RETURN 2017
#define ID_CLASS 2018
#define ID_EXTENDS 2019
#define ID_SYNCHO 2020
#define ID_NEW 2021
#define ID_PUBLIC 2022
#define ID_EXTERN 2023
#define ID_FINAL 2024
#define ID_STATIC 2025
#define ID_PROTECTED 2026
#define ID_PRIVATE 2027
#define ID_REPEAT 2028
#define ID_DEBUGDD 2099
#define ID_INT 2100
#define ID_FLOAT 2101
#define ID_BOOLEAN 2102
#define ID_STRING 2103
#define ID_VOID 2104
#define ID_BOOL 2105
#define ID_TRUE 2200
#define ID_FALSE 2201
#define ID_NULL 2202
#define ID_NAN 2203
#define ID_OPENPAR 2300
#define ID_CLOSEPAR 2301
#define ID_OPBLK 2302
#define ID_CLBLK 2303
#define ID_SEP 2304
#define ID_COMMA 2305
#define ID_DOTS 2306
#define ID_DOT 2307
#define ID_OPBRK 2308
#define ID_CLBRK 2309
#define ID_DBLDOTS 2310
#define ID_LOGIC 2311
#define ID_ADD 2312
#define ID_SUB 2313
#define ID_MUL 2314
#define ID_DIV 2315
#define ID_ASS 2316
#define ID_ASSADD 2317
#define ID_ASSSUB 2318
#define ID_ASSMUL 2319
#define ID_ASSDIV 2320
#define ID_ASSOR 2321
#define ID_ASSAND 2322
#define ID_ASSXOR 2323
#define ID_ASSSL 2324
#define ID_ASSSR 2325
#define ID_ASSASR 2326
#define ID_SL 2327
#define ID_SR 2328
#define ID_ASR 2329
#define ID_INC 2330
#define ID_DEC 2331
#define ID_LO 2332
#define ID_HI 2333
#define ID_LS 2334
#define ID_HS 2335
#define ID_EQ 2336
#define ID_NE 2337
#define ID_AND 2338
#define ID_XOR 2339
#define ID_OR 2340
#define ID_LOG_AND 2341
#define ID_LOG_OR 2342
#define ID_LOG_NOT 2343
#define ID_NOT 2344
#define ID_MODULO 2345
#define ID_POWER 2346
#define ID_ASSMODULO 2347
#define TX_UNDEF 4000
#define TX_NAN 4001
#define TX_OPENPAR 5000
#define TX_CLOSEPAR 5001
#define TX_NOTBOOL 5002
#define TX_UNDEFVAR 5003
#define TX_BADLEFT 5004
#define TX_ENDOF 5005
#define TX_OUTCASE 5006
#define TX_NOTERM 5007
#define TX_CLOSEBLK 5008
#define TX_ELSEWITHOUTIF 5009
#define TX_OPENBLK 5010
#define TX_BADTYPE 5011
#define TX_REDEFVAR 5012
#define TX_BAD2TYPE 5013
#define TX_UNDEFCALL 5014
#define TX_MISDOTS 5015
#define TX_WHILE 5016
#define TX_BREAK 5017
#define TX_LABEL 5018
#define TX_NOLABEL 5019
#define TX_NOCASE 5020
#define TX_BADNUM 5021
#define TX_VOID 5022
#define TX_NOTYP 5023
#define TX_NOVAR 5024
#define TX_NOFONC 5025
#define TX_OVERPARAM 5026
#define TX_REDEF 5027
#define TX_LOWPARAM 5028
#define TX_BADPARAM 5029
#define TX_NUMPARAM 5030
#define TX_NOITEM 5031
#define TX_DOT 5032
#define TX_NOCONST 5033
#define TX_REDEFCLASS 5034
#define TX_CLBRK 5035
#define TX_RESERVED 5036
#define TX_BADNEW 5037
#define TX_OPBRK 5038
#define TX_BADSTRING 5039
#define TX_BADINDEX 5040
#define TX_PRIVATE 5041
#define TX_NOPUBLIC 5042
#define TX_DIVZERO 6000
#define TX_NOTINIT 6001
#define TX_BADTHROW 6002
#define TX_NORETVAL 6003
#define TX_NORUN 6004
#define TX_NOCALL 6005
#define TX_NOCLASS 6006
#define TX_NULLPT 6007
#define TX_OPNAN 6008
#define TX_OUTARRAY 6009
#define TX_STACKOVER 6010
#define TX_DELETEDPT 6011
#define TX_FILEOPEN 6012
#define TX_NOTOPEN 6013
#define TX_ERRREAD 6014
#define TX_ERRWRITE 6015
#define ID_SUPER 62020
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
#pragma once
#ifndef _RESOURCE_H_
#define _RESOURCE_H_
enum EID
{
ID_IF = 2000,
ID_ELSE,
ID_WHILE,
ID_DO,
ID_FOR,
ID_BREAK,
ID_CONTINUE,
ID_SWITCH,
ID_CASE,
ID_DEFAULT,
ID_TRY,
ID_THROW,
ID_CATCH,
ID_FINALLY,
ID_TXT_AND,
ID_TXT_OR,
ID_TXT_NOT,
ID_RETURN,
ID_CLASS,
ID_EXTENDS,
ID_SYNCHO,
ID_NEW,
ID_PUBLIC,
ID_EXTERN,
ID_FINAL,
ID_STATIC,
ID_PROTECTED,
ID_PRIVATE,
ID_REPEAT,
ID_DEBUGDD,
ID_INT,
ID_FLOAT,
ID_BOOLEAN,
ID_STRING,
ID_VOID,
ID_BOOL,
ID_TRUE = 2200,
ID_FALSE,
ID_NULL,
ID_NAN,
ID_OPENPAR = 2300,
ID_CLOSEPAR,
ID_OPBLK,
ID_CLBLK,
ID_SEP,
ID_COMMA,
ID_DOTS,
ID_DOT,
ID_OPBRK,
ID_CLBRK,
ID_DBLDOTS,
ID_LOGIC,
ID_ADD,
ID_SUB,
ID_MUL,
ID_DIV,
ID_ASS,
ID_ASSADD,
ID_ASSSUB,
ID_ASSMUL,
ID_ASSDIV,
ID_ASSOR,
ID_ASSAND,
ID_ASSXOR,
ID_ASSSL,
ID_ASSSR,
ID_ASSASR,
ID_SL,
ID_SR,
ID_ASR,
ID_INC,
ID_DEC,
ID_LO,
ID_HI,
ID_LS,
ID_HS,
ID_EQ,
ID_NE,
ID_AND,
ID_XOR,
ID_OR,
ID_LOG_AND,
ID_LOG_OR,
ID_LOG_NOT,
ID_NOT,
ID_MODULO,
ID_POWER,
ID_ASSMODULO,
TX_UNDEF = 4000,
TX_NAN,
ID_SUPER = 6000
};
#define TX_OPENPAR 5000
#define TX_CLOSEPAR 5001
#define TX_NOTBOOL 5002
#define TX_UNDEFVAR 5003
#define TX_BADLEFT 5004
#define TX_ENDOF 5005
#define TX_OUTCASE 5006
#define TX_NOTERM 5007
#define TX_CLOSEBLK 5008
#define TX_ELSEWITHOUTIF 5009
#define TX_OPENBLK 5010
#define TX_BADTYPE 5011
#define TX_REDEFVAR 5012
#define TX_BAD2TYPE 5013
#define TX_UNDEFCALL 5014
#define TX_MISDOTS 5015
#define TX_WHILE 5016
#define TX_BREAK 5017
#define TX_LABEL 5018
#define TX_NOLABEL 5019
#define TX_NOCASE 5020
#define TX_BADNUM 5021
#define TX_VOID 5022
#define TX_NOTYP 5023
#define TX_NOVAR 5024
#define TX_NOFONC 5025
#define TX_OVERPARAM 5026
#define TX_REDEF 5027
#define TX_LOWPARAM 5028
#define TX_BADPARAM 5029
#define TX_NUMPARAM 5030
#define TX_NOITEM 5031
#define TX_DOT 5032
#define TX_NOCONST 5033
#define TX_REDEFCLASS 5034
#define TX_CLBRK 5035
#define TX_RESERVED 5036
#define TX_BADNEW 5037
#define TX_OPBRK 5038
#define TX_BADSTRING 5039
#define TX_BADINDEX 5040
#define TX_PRIVATE 5041
#define TX_NOPUBLIC 5042
#define TX_DIVZERO 6000
#define TX_NOTINIT 6001
#define TX_BADTHROW 6002
#define TX_NORETVAL 6003
#define TX_NORUN 6004
#define TX_NOCALL 6005
#define TX_NOCLASS 6006
#define TX_NULLPT 6007
#define TX_OPNAN 6008
#define TX_OUTARRAY 6009
#define TX_STACKOVER 6010
#define TX_DELETEDPT 6011
#define TX_FILEOPEN 6012
#define TX_NOTOPEN 6013
#define TX_ERRREAD 6014
#define TX_ERRWRITE 6015
#endif //_RESOURCE_H_

View File

@ -26,7 +26,7 @@
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
#include "resource.h" // main symbols
//#include "../CbotDll.h" // librairie CBot
#include "../Cbot.h" // complet pour Browse
@ -43,7 +43,7 @@ public:
CTestCBotApp();
CEdit* m_pConsole;
CTestCBotView* m_LastActive;
CTestCBotView* m_LastActive;
CBotClass* m_pClassPoint;
CBotClass* m_pClassPointIntr;

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,96 @@
object radarGuepe(point orig, float dist)
{
int i;
object pr, r;
float mindist;
i = 0;
mindist = 1000;
while (i<30)
{
pr = radar(i);
if (pr != null)
{
if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3)
{
mindist = distance(orig, pr.position);
r = pr;
}
}
i = i+1;
}
if (mindist < dist) return(r); else return(null);
}
class Guepe
{
point pos;
void cherche(point orig, float dist)
{
object p;
point o;
p = radarGuepe(orig, dist);
while (p == null)
{
wait(0.1);
p = radarGuepe(orig, dist);
}
pos.x = p.position.x;
pos.y = p.position.y;
pos.z = p.position.z;
//o = p.position;
//wait(0.1);
//vitessex = (p.position.x - o.x)/0.1;
//vitessey = (p.position.y - o.y)/0.1;
//vitessez = (p.position.z - o.z)/0.1;
}
void tire(point orig, float orient)
{
//float t = 3; //temps d'anticipation
float angle;
point cible;
cible.x = pos.x;// + t*vitessex;
cible.y = pos.y;// + t*vitessey;
cible.z = pos.z;// + t*vitessez;
if (cible.x == 0) angle = 90; else
angle = atan(cible.y / cible.x);
if (cible.x < 0) angle = angle + 180;
angle = angle - orient;
if (angle > 180) angle = angle - 360;
if (angle < -180) angle = angle + 360;
turn(angle);
angle = atan((cible.z-orig.z) / distance2d(orig, cible));
aim(angle);
fire(0.1);
}
}
extern void object::Fourmi6()
{
//fps(1000);
Guepe guepe = new Guepe();
while (true)
{
guepe.cherche(position, 50);
guepe.tire(position, orientation);
}
}

View File

@ -0,0 +1,96 @@
object radarGuepe(point orig, float dist)
{
int i;
object pr, r;
float mindist;
i = 0;
mindist = 1000;
while (i<30)
{
pr = radar(i);
if (pr != null)
{
if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3)
{
mindist = distance(orig, pr.position);
r = pr;
}
}
i = i+1;
}
if (mindist < dist) return(r); else return(null);
}
class Guepe
{
point pos;
void cherche(point orig, float dist)
{
object p;
point o;
p = radarGuepe(orig, dist);
while (p == null)
{
wait(0.1);
p = radarGuepe(orig, dist);
}
pos.x = p.position.x;
pos.y = p.position.y;
pos.z = p.position.z;
//o = p.position;
//wait(0.1);
//vitessex = (p.position.x - o.x)/0.1;
//vitessey = (p.position.y - o.y)/0.1;
//vitessez = (p.position.z - o.z)/0.1;
}
void tire(point orig, float orient)
{
//float t = 3; //temps d'anticipation
float angle;
point cible;
cible.x = pos.x;// + t*vitessex;
cible.y = pos.y;// + t*vitessey;
cible.z = pos.z;// + t*vitessez;
if (cible.x == 0) angle = 90; else
angle = atan(cible.y / cible.x);
if (cible.x < 0) angle = angle + 180;
angle = angle - orient;
if (angle > 180) angle = angle - 360;
if (angle < -180) angle = angle + 360;
turn(angle);
angle = atan((cible.z-orig.z) / distance2d(orig, cible));
aim(angle);
fire(0.1);
}
}
extern void object::Fourmi6()
{
//fps(1000);
Guepe guepe = new Guepe();
while (true)
{
guepe.cherche(position, 50);
guepe.tire(position, orientation);
}
}

Some files were not shown because too many files have changed in this diff Show More