From 650923a784d7e99ad92018deed326199d9d1bcd5 Mon Sep 17 00:00:00 2001 From: Ben Lynn Date: Thu, 18 Apr 2002 17:55:26 -0700 Subject: [PATCH] Wed Apr 17 01:05:42 PDT 2002 Started. Thu Apr 18 17:55:26 PDT 2002 Playable. ... Cleanup in preparation for release. [netwalk-0.1.tgz] --- HISTORY | 11 + LICENSE | 340 +++++++++++++++++++++++++++++++ Makefile | 53 +++++ README | 18 ++ bl_lib.c | 20 ++ bl_lib.h | 4 + cecil.se | 3 + color.e | 38 ++++ color_table.e | 52 +++++ config.e | 7 + config_data.e | 57 ++++++ cross.ed | 4 + dir_constant.e | 21 ++ event.e | 38 ++++ eventmaker.e | 20 ++ ext_sdl.c | 156 ++++++++++++++ image.e | 137 +++++++++++++ linux.config | 2 + netwalk.e | 629 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sdl_constant.e | 301 +++++++++++++++++++++++++++ tile.e | 72 +++++++ ttf_font.e | 54 +++++ version.h | 21 ++ win32.config | 2 + 24 files changed, 2060 insertions(+) create mode 100644 HISTORY create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100644 bl_lib.c create mode 100644 bl_lib.h create mode 100644 cecil.se create mode 100644 color.e create mode 100644 color_table.e create mode 100644 config.e create mode 100644 config_data.e create mode 100644 cross.ed create mode 100644 dir_constant.e create mode 100644 event.e create mode 100644 eventmaker.e create mode 100644 ext_sdl.c create mode 100644 image.e create mode 100644 linux.config create mode 100644 netwalk.e create mode 100644 sdl_constant.e create mode 100644 tile.e create mode 100644 ttf_font.e create mode 100644 version.h create mode 100644 win32.config diff --git a/HISTORY b/HISTORY new file mode 100644 index 0000000..150c9ee --- /dev/null +++ b/HISTORY @@ -0,0 +1,11 @@ +Wed Apr 17 01:05:42 PDT 2002 + Started. + +Thu Apr 18 17:55:26 PDT 2002 + Playable. + + ... + + Cleanup in preparation for release. + + [netwalk-0.1.tgz] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5b6e7c6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..58c562e --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +ALLFILES = ext_sdl.c bl*.[ch] version.h *.e Makefile LICENSE README HISTORY *.config *.se cross.ed + +ifdef WIN32 +CC = i586-mingw32msvc-gcc +EFLAGS=-boost -O2 -I /home/ben/cross/SDL/include/SDL +CFLAGS=-O2 -Wall -I /home/ben/cross/SDL/include/SDL +SDL_LIBS=-L /home/ben/cross/SDL/lib -lSDL +LIBS = $(SDL_LIBS) -lSDL_ttf +else +CC = gcc +CFLAGS=-O2 -Wall `sdl-config --cflags` +EFLAGS=-boost -O2 `sdl-config --cflags` +SDL_LIBS=`sdl-config --libs` +LIBS = $(SDL_LIBS) -lSDL_ttf +endif + +target : netwalk + +bl_lib.o : bl_lib.c + +netwalk : *.e ext_sdl.c bl_lib.o +ifdef WIN32 + compile_to_c -cecil cecil.se -o $@.exe netwalk $(EFLAGS) ext_sdl.c bl_lib.o $(LIBS) + ed -s netwalk.make < cross.ed + . netwalk.make +else + compile -cecil cecil.se $(EFLAGS) -o $@ netwalk ext_sdl.c bl_lib.o $(LIBS) +endif + +clean : + -rm netwalk *.o + clean netwalk + +projname := $(shell awk '/NETWALK_VERSION/ { print $$3 }' version.h ) + +dist: $(ALLFILES) + -rm -rf $(projname) + mkdir $(projname) + cp -rl --parents $(ALLFILES) $(projname) + tar chfz $(projname).tgz $(projname) + -rm -rf $(projname) + +ifdef WIN32 +windist : netwalk + -rm -rf $(projname) + mkdir $(projname) + cp -l netwalk.exe $(projname) + cp -l linux.config $(projname)/config + cp -l /home/ben/cross/SDL/lib/SDL.dll $(projname) + cp -l /home/ben/cross/SDL/lib/SDL_ttf.dll $(projname) + zip $(projname)-win.zip $(projname)/* + -rm -rf $(projname) +endif diff --git a/README b/README new file mode 100644 index 0000000..39f9ebd --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +README for NetWalk v0.1 + +I tried a shareware Windows game called NetWalk once. I liked the idea so +I decided to implement my own so I could play in Linux, and customize it more. + +NetWalk is a puzzle game where the object is to connect every terminal to the +main server. (These are represented by coloured boxes, so I guess you could +also imagine them to be water mains, electricity cables, phone lines, etc.) +Clicking on a square will rotate its contents, a left click performs an +anticlockwise rotation and a right click performs a clockwise rotation. + +In this version, not only must every terminal be connected, but every piece of +cable must also be connected to the main server somehow. + +The interface is quite bare at the moment. Press F2 to start a new game, +F3 to toggle pipe wrap, and Escape to quit. + +Ben Lynn diff --git a/bl_lib.c b/bl_lib.c new file mode 100644 index 0000000..018261f --- /dev/null +++ b/bl_lib.c @@ -0,0 +1,20 @@ +#include +#include +#include + +void *bl_malloc(size_t size) +{ + void *result; + + result = malloc(size); + if (!result) { + perror("malloc"); + exit(1); + } + return result; +} + +void bl_free(void *ptr) +{ + free(ptr); +} diff --git a/bl_lib.h b/bl_lib.h new file mode 100644 index 0000000..3bc182c --- /dev/null +++ b/bl_lib.h @@ -0,0 +1,4 @@ +#define bl_new(type) (type *) bl_malloc(sizeof (type)); + +void *bl_malloc(size_t size); +void bl_free(void *ptr); diff --git a/cecil.se b/cecil.se new file mode 100644 index 0000000..0c6ac3e --- /dev/null +++ b/cecil.se @@ -0,0 +1,3 @@ +eiffel.h +EVENTMAKER_make_keydown EVENTMAKER make_keydown +EVENTMAKER_make_mbdown EVENTMAKER make_mbdown diff --git a/color.e b/color.e new file mode 100644 index 0000000..168e3d7 --- /dev/null +++ b/color.e @@ -0,0 +1,38 @@ +class COLOR +creation make +feature + make(r, g, b : INTEGER) is + do + pointer := ext_make_color(r, g, b) + to_integer := ext_convert_color(r, g, b) + to_gfx_integer := r * 256 * 256 * 256 + g * 256 * 256 + b * 256 + 255 + end + + free is + do + ext_free_color(pointer) + end + + to_external : POINTER is + do + Result := pointer + end + + to_integer : INTEGER + + to_gfx_integer : INTEGER + + pointer : POINTER + + ext_make_color(r, g, b : INTEGER) : POINTER is + external "C" + end + + ext_free_color(p : POINTER) is + external "C" alias "free" + end + + ext_convert_color(r, g, b : INTEGER) : INTEGER is + external "C" + end +end diff --git a/color_table.e b/color_table.e new file mode 100644 index 0000000..0385975 --- /dev/null +++ b/color_table.e @@ -0,0 +1,52 @@ +deferred class COLOR_TABLE +feature + black : COLOR is + once + !!Result.make(0, 0, 0) + end + + white : COLOR is + once + !!Result.make(255, 255, 255) + end + + darkred : COLOR is + once + !!Result.make(127, 0, 0) + end + + red : COLOR is + once + !!Result.make(255, 0, 0) + end + + cyan : COLOR is + once + !!Result.make(0, 255, 255) + end + + yellow : COLOR is + once + !!Result.make(255, 255, 0) + end + + purple : COLOR is + once + !!Result.make(255, 0, 255) + end + + blue : COLOR is + once + !!Result.make(0, 0, 255) + end + + green : COLOR is + once + !!Result.make(0, 255, 0) + end + + darkpurple : COLOR is + once + !!Result.make(127, 0, 127) + end +end diff --git a/config.e b/config.e new file mode 100644 index 0000000..4259890 --- /dev/null +++ b/config.e @@ -0,0 +1,7 @@ +deferred class CONFIG +feature + config : CONFIG_DATA is + once + !!Result.make + end +end diff --git a/config_data.e b/config_data.e new file mode 100644 index 0000000..7c44c35 --- /dev/null +++ b/config_data.e @@ -0,0 +1,57 @@ +class CONFIG_DATA +creation make +feature + config_file : STRING is "config" + + mainttf : STRING + bigttf : STRING + + mainfont : TTF_FONT + bigfont : TTF_FONT + + make is + do + load_config + end + + load_config is + local + in : TEXT_FILE_READ + do + !!in.connect_to(config_file) + if not in.is_connected then + io.put_string("couldn't read config file%N") + die_with_code(1) + else + read_config(in) + end + in.disconnect + end + + read_config(in : TEXT_FILE_READ) is + local + s1, s2 : STRING + do + from in.read_word + until in.end_of_input + loop + s1 := clone(in.last_string) + if not in.end_of_input then + in.read_line + s2 := clone(in.last_string) + else + !!s2.copy("") + end + if s1.first = '#' then + elseif s1.is_equal("main_font") then + mainttf := s2 + elseif s1.is_equal("big_font") then + bigttf := s2 + end + in.read_word + end + + !!mainfont.load(mainttf, 12) + !!bigfont.load(bigttf, 24) + end +end diff --git a/cross.ed b/cross.ed new file mode 100644 index 0000000..263488c --- /dev/null +++ b/cross.ed @@ -0,0 +1,4 @@ +%s/gcc/i586-mingw32msvc-gcc/ +%s/strip/i586-mingw32msvc-strip/ +w +q diff --git a/dir_constant.e b/dir_constant.e new file mode 100644 index 0000000..6857439 --- /dev/null +++ b/dir_constant.e @@ -0,0 +1,21 @@ +deferred class DIR_CONSTANT +feature + dir_up : INTEGER is 1 + dir_right : INTEGER is 2 + dir_down : INTEGER is 3 + dir_left : INTEGER is 4 + + dir_opposite(dir : INTEGER) : INTEGER is + do + inspect dir + when dir_up then + Result := dir_down + when dir_down then + Result := dir_up + when dir_left then + Result := dir_right + when dir_right then + Result := dir_left + end + end +end diff --git a/event.e b/event.e new file mode 100644 index 0000000..cb4ff94 --- /dev/null +++ b/event.e @@ -0,0 +1,38 @@ +class EVENT +creation make +feature + x, y : INTEGER + type : INTEGER + i1, i2 : INTEGER + kmod : INTEGER + + make is + do + end + + put_xy(x0, y0 : INTEGER) is + do + x := x0 + y := y0 + end + + put_type(i : INTEGER) is + do + type := i + end + + put_i1(i : INTEGER) is + do + i1 := i + end + + put_i2(i : INTEGER) is + do + i2 := i + end + + put_kmod(i : INTEGER) is + do + kmod := i + end +end diff --git a/eventmaker.e b/eventmaker.e new file mode 100644 index 0000000..b227b93 --- /dev/null +++ b/eventmaker.e @@ -0,0 +1,20 @@ +expanded class EVENTMAKER +inherit SDL_CONSTANT +feature + make_keydown(key : INTEGER; kmod : INTEGER) : EVENT is + do + !!Result.make + Result.put_type(sdl_keydown) + Result.put_i1(key) + Result.put_kmod(kmod) + end + + make_mbdown(b : INTEGER; kmod : INTEGER; x, y : INTEGER) : EVENT is + do + !!Result.make + Result.put_type(sdl_mousebuttondown) + Result.put_i1(b) + Result.put_kmod(kmod) + Result.put_xy(x, y) + end +end diff --git a/ext_sdl.c b/ext_sdl.c new file mode 100644 index 0000000..5bb0104 --- /dev/null +++ b/ext_sdl.c @@ -0,0 +1,156 @@ +#include +#include +#include +#include +#include +#include "bl_lib.h" +#include "version.h" +#include "eiffel.h" + +static SDL_Surface *screen; + +void ext_fill_rect(int x, int y, int w, int h, int c) +{ + SDL_Rect rect; + + rect.x = x; + rect.y = y; + rect.w = w; + rect.h = h; + SDL_FillRect(screen, &rect, c); +} + +void video_init() +{ + + //screen = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); + screen = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE | SDL_DOUBLEBUF); + //screen = SDL_SetVideoMode(640, 480, 0, SDL_SWSURFACE | SDL_FULLSCREEN); + if (!screen) { + fprintf(stderr, "Can't set video mode: %s\n", SDL_GetError()); + exit(1); + } + //SDL_ShowCursor(SDL_DISABLE); +} + +void ext_init() +{ + int status; + + //printf("SDL_Init()...\n"); + //status = SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER); + status = SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER); + if (status < 0) { + fprintf(stderr, "Can't init SDL: %s\n", SDL_GetError()); + exit(1); + } + atexit(SDL_Quit); + //printf("TTF_Init()...\n"); + status = TTF_Init(); + if (status) { + fprintf(stderr, "init_glue: TTF_Init failed: %s\n", SDL_GetError()); + exit(-1); + } + atexit(TTF_Quit); + + video_init(); + + signal(SIGINT, exit); + signal(SIGTERM, exit); + + SDL_WM_SetCaption(NETWALK_VERSION, NETWALK_VERSION); + + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); +} + +void ext_update_screen() +{ + SDL_Flip(screen); +} + +EIF_OBJ ext_poll_event(EIF_OBJ em) +{ + SDL_Event event; + + while (SDL_PollEvent(&event)) { + if (event.type == SDL_KEYDOWN) { + return EVENTMAKER_make_keydown(em, event.key.keysym.sym, SDL_GetModState()); + } else if (event.type == SDL_MOUSEBUTTONDOWN) { + return EVENTMAKER_make_mbdown(em, event.button.button, SDL_GetModState(), event.button.x, event.button.y); + } + } + return NULL; +} + +int is_kmod(int a, int b) +{ + return (a & b) != 0; +} + +SDL_Surface *ext_render_text(char *s, TTF_Font *font, SDL_Color *c) +{ + SDL_Surface *tmp; + SDL_Surface *res; + + tmp = TTF_RenderText_Solid(font, s, *c); + res = SDL_DisplayFormat(tmp); + SDL_FreeSurface(tmp); + return res; +} + +void *ext_make_color(int r, int g, int b) +{ + SDL_Color *res; + + res = (SDL_Color *) bl_malloc(sizeof(SDL_Color)); + res->r = r; + res->g = g; + res->b = b; + + return res; +} + +int ext_convert_color(int r, int g, int b) +{ + return SDL_MapRGB(screen->format, r, g, b); +} + +void blit_img(SDL_Surface *image, int x, int y) +{ + SDL_Rect rect; + + rect.x = x; + rect.y = y; + SDL_BlitSurface(image, NULL, screen, &rect); +} + +SDL_Surface *ext_display_format_alpha(SDL_Surface *img) +{ + SDL_Surface *res; + + //assert(img); + res = SDL_DisplayFormatAlpha(img); + SDL_FreeSurface(img); + return res; +} + +SDL_Surface *ext_display_format(SDL_Surface *img) +{ + SDL_Surface *res; + + //assert(img); + res = SDL_DisplayFormat(img); + SDL_FreeSurface(img); + return res; +} + +TTF_Font *ext_ttf_openfont(char *font, int size) +{ + return TTF_OpenFont(font, size); +} + +void *free_ttf_font(TTF_Font *font) +{ + TTF_CloseFont(font); + return NULL; +} diff --git a/image.e b/image.e new file mode 100644 index 0000000..aa56b21 --- /dev/null +++ b/image.e @@ -0,0 +1,137 @@ +class IMAGE +creation make +feature + make is + do + end + + width : INTEGER is + require + is_connected + do + Result := get_img_width(ptr) + end + + height : INTEGER is + require + is_connected + do + Result := get_img_height(ptr) + end + + is_connected : BOOLEAN + + load(filename : STRING) is + do + ptr := load_image(filename.to_external) + if ptr.is_not_null then + is_connected := True + end + end + + free is + require + is_connected + do + if ptr.is_not_null then + ptr := free_img(ptr) + is_connected := False + end + end + + partial_blit(rx, ry, rw, rh, x, y : INTEGER) is + require + is_connected + do + partial_blit_img(ptr, rx, ry, rw, rh, x, y) + end + + blit(x, y : INTEGER) is + require + is_connected + do + blit_img(ptr, x, y) + end + + render_string(s : STRING; font : TTF_FONT; c : COLOR) is + require + not is_connected --otherwise it's a memory leak + font.is_connected + s /= Void + s.count > 0 + do + ptr := ext_render_text(s.to_external, font.to_external, c.to_external) + if ptr.is_not_null then + is_connected := True + convert_display_format + else + io.put_string("render_string " + s.count.to_string + " failed!%N") + end + ensure + is_connected + end + + set_alpha(a : INTEGER) is + require + is_connected + do + img_set_alpha(ptr, a) + end + + convert_display_format_alpha is + require + is_connected + do + ptr := ext_display_format_alpha(ptr) + end + + convert_display_format is + require + is_connected + do + ptr := ext_display_format(ptr) + end + +feature {NONE} + ptr : POINTER + + load_image(filename : POINTER) : POINTER is + external "C" + end + + free_img(i : POINTER) : POINTER is + external "C" + end + + ext_render_text(string : POINTER; font : POINTER; c : POINTER) : POINTER is + external "C" + end + + get_img_width(i : POINTER) : INTEGER is + external "C" + end + + get_img_height(i : POINTER) : INTEGER is + external "C" + end + + img_set_alpha(i : POINTER; a : INTEGER) is + external "C" + end + + partial_blit_img(i : POINTER; rx, ry, rw, rh, x, y : INTEGER) is + external "C" + end + + blit_img(i : POINTER; x, y : INTEGER) is + external "C" + end + + ext_display_format_alpha(p : POINTER) : POINTER is + external "C" + end + + ext_display_format(p : POINTER) : POINTER is + external "C" + end +end diff --git a/linux.config b/linux.config new file mode 100644 index 0000000..331897a --- /dev/null +++ b/linux.config @@ -0,0 +1,2 @@ +main_font /usr/share/fonts/truetype/Arial.ttf +big_font /usr/share/fonts/truetype/Impact.ttf diff --git a/netwalk.e b/netwalk.e new file mode 100644 index 0000000..f247567 --- /dev/null +++ b/netwalk.e @@ -0,0 +1,629 @@ +--TODO: similar code: get_neighbour, is_surrounded. need TUPLEs? +class NETWALK +inherit DIR_CONSTANT; SDL_CONSTANT; COLOR_TABLE; CONFIG +creation make +feature + tile_server_top : INTEGER is 1 + tile_server_bottom : INTEGER is 2 + tile_normal : INTEGER is 3 + tile_terminal : INTEGER is 4 + + board : ARRAY2[TILE] + width : INTEGER + height : INTEGER + servertopi : INTEGER is + do + Result := width // 2 + end + servertopj : INTEGER is + do + Result := height // 2 + 1 + end + + font : TTF_FONT is + do + Result := config.bigfont + end + + win_image : IMAGE is + once + !!Result.make + Result.render_string("Well Done", font, white) + end + + allow_wrap : BOOLEAN + difficulty : INTEGER + + seed : INTEGER + + make is + do + !!rand.make + ext_init + connected_pipe_color := green + disconnected_pipe_color := darkred + connected_terminal_color := cyan + disconnected_terminal_color := darkpurple + width := 10 + height := 9 + main_loop + end + + new_game is + do + rand.with_seed(seed) + !!board.make(1, width, 1, height) + generate_board + preprocess_board + scramble_board + game_state := state_playing + if difficulty > 0 then + allow_wrap := True + else + allow_wrap := False + end + end + + state_none : INTEGER is 0 + state_playing : INTEGER is 1 + state_victory : INTEGER is 2 + state_quit : INTEGER is 3 + game_state : INTEGER + + main_loop is + local + e : EVENT + do + from + until game_state = state_quit + loop + seed := seed + 1 + blank_screen + draw_border + if game_state = state_playing then + draw_board + if check_connections then + game_state := state_victory + end + end + if game_state = state_victory then + draw_board + win_image.blit(50, 400) + end + ext_update_screen + e := poll_event + if e /= Void then + handle_event(e) + end + end + end + + handle_event(e : EVENT) is + do + inspect e.type + when sdl_keydown then + inspect e.i1 + when sdlk_escape then + game_state := state_quit + when sdlk_f3 then + difficulty := difficulty + 1 + if difficulty > 1 then + difficulty := 0 + end + when sdlk_f2 then + new_game + else + end + when sdl_mousebuttondown then + handle_mbdown(e) + else + end + end + + handle_mbdown(e : EVENT) is + local + i, j : INTEGER + do + if game_state = state_playing then + i := e.x // cellwidth + j := e.y // cellheight + if on_board(i, j) then + if e.i1 = 1 then + rotateccw(i, j) + else + rotatecw(i, j) + end + end + end + end + + rotatecw(i, j : INTEGER) is + local + t : TILE + dir : INTEGER + bak : BOOLEAN + do + t := board.item(i, j) + if t = server_top or else t = server_bottom then + bak := server_top.neighbour.item(1) + server_top.neighbour.put(server_bottom.neighbour.item(4), 1) + server_bottom.neighbour.put(server_bottom.neighbour.item(3), 4) + server_bottom.neighbour.put(server_bottom.neighbour.item(2), 3) + server_bottom.neighbour.put(bak, 2) + elseif t /= Void then + bak := t.neighbour.item(4) + from dir := 4 + until dir = 1 + loop + t.neighbour.put(t.neighbour.item(dir - 1), dir) + dir := dir - 1 + end + t.neighbour.put(bak, dir) + end + end + + rotateccw(i, j : INTEGER) is + local + t : TILE + dir : INTEGER + bak : BOOLEAN + do + t := board.item(i, j) + if t = server_top or else t = server_bottom then + bak := server_top.neighbour.item(1) + server_top.neighbour.put(server_bottom.neighbour.item(2), 1) + server_bottom.neighbour.put(server_bottom.neighbour.item(3), 2) + server_bottom.neighbour.put(server_bottom.neighbour.item(4), 3) + server_bottom.neighbour.put(bak, 4) + elseif t /= Void then + bak := t.neighbour.item(1) + from dir := 1 + until dir = 4 + loop + t.neighbour.put(t.neighbour.item(dir + 1), dir) + dir := dir + 1 + end + t.neighbour.put(bak, dir) + end + end + + server_top, server_bottom : TILE + + preprocess_board is + local + i, j : INTEGER + t : TILE + do + from i := 1 + until i > width + loop + from j := 1 + until j > height + loop + t := board.item(i, j) + if t /= Void then + t.count_neighbours + end + j := j + 1 + end + i := i + 1 + end + end + + draw_board is + local + i, j : INTEGER + do + from i := 1 + until i > width + loop + from j := 1 + until j > height + loop + draw_tile(board.item(i, j)) + j := j + 1 + end + i := i + 1 + end + end + + draw_border is + local + i : INTEGER + do + from i := 1 + until i > width + 1 + loop + fill_rect(i * cellwidth, cellheight, 1, height * cellheight, blue) + i := i + 1 + end + + from i := 1 + until i > height + 1 + loop + fill_rect(cellwidth, i * cellheight, width * cellwidth, 1, blue) + i := i + 1 + end + end + + cellwidth : INTEGER is 32 + cellheight : INTEGER is 32 + uppipex : INTEGER is 13 + uppipew : INTEGER is 6 + uppipeh : INTEGER is 19 + leftpipey : INTEGER is 13 + leftpipew : INTEGER is 19 + leftpipeh : INTEGER is 6 + + check_connections : BOOLEAN is + local + check_list : LINKED_LIST[TILE] + i, j : INTEGER + dir : INTEGER + t, t2 : TILE + do + from i := 1 + until i > width + loop + from j := 1 + until j > height + loop + t := board.item(i, j) + if t /= Void then + t.disconnect + end + j := j + 1 + end + i := i + 1 + end + + !!check_list.make + check_list.add_last(server_top) + check_list.add_last(server_bottom) + server_top.connect + server_bottom.connect + + from + until check_list.is_empty + loop + t := check_list.first + check_list.remove_first + from dir := 1 + until dir > 4 + loop + if t.neighbour.item(dir) then + t2 := get_neighbour(t, dir) + if t2 /= Void and then + t2.neighbour.item(dir_opposite(dir)) and then + not t2.is_connected then + t2.connect + check_list.add_last(t2) + end + end + dir := dir + 1 + end + end + + --victory check + Result := True + from i := 1 + until i > width or else not Result + loop + from j := 1 + until j > height or else not Result + loop + t := board.item(i, j) + if t /= Void and then not t.is_connected then + Result := False + end + j := j + 1 + end + i := i + 1 + end + end + + maybe_wrapx(i : INTEGER) : INTEGER is + do + Result := i + if allow_wrap then + if i < 1 then + Result := i + width + elseif i > width then + Result := i - width + end + end + end + + maybe_wrapy(i : INTEGER) : INTEGER is + do + Result := i + if allow_wrap then + if i < 1 then + Result := i + height + elseif i > height then + Result := i - height + end + end + end + + get_neighbour(t : TILE; dir : INTEGER) : TILE is + local + x, y : INTEGER + x1, y1 : INTEGER + do + if dir = dir_up then + y1 := -1 + elseif dir = dir_down then + y1 := 1 + end + + if dir = dir_left then + x1 := -1 + elseif dir = dir_right then + x1 := 1 + end + x := maybe_wrapx(t.x + x1) + y := maybe_wrapy(t.y + y1) + if on_board(x, y) then + Result := board.item(x, y) + end + end + + on_board(x, y : INTEGER) : BOOLEAN is + do + Result := x >= 1 and then x <= width + and then y >= 1 and then y <= height + end + + connected_pipe_color : COLOR + disconnected_pipe_color : COLOR + connected_terminal_color : COLOR + disconnected_terminal_color : COLOR + + draw_tile(tile : TILE) is + local + x : INTEGER + y : INTEGER + c, c2 : COLOR + do + if tile /= Void then + x := tile.x * cellwidth + y := tile.y * cellheight + if tile.is_connected then + c := connected_pipe_color + c2 := connected_terminal_color + else + c := disconnected_pipe_color + c2 := disconnected_terminal_color + end + + if tile.neighbour.item(dir_up) then + fill_rect(x + uppipex, y, uppipew, uppipeh, c) + end + if tile.neighbour.item(dir_left) then + fill_rect(x, y + leftpipey, leftpipew, leftpipeh, c) + end + if tile.neighbour.item(dir_right) then + fill_rect(x + uppipex, y + leftpipey, leftpipew, leftpipeh, c) + end + if tile.neighbour.item(dir_down) then + fill_rect(x + uppipex, y + leftpipey, uppipew, uppipeh, c) + end + + inspect tile.type + when tile_server_top then + fill_rect(x + 5, y + 5, cellwidth - 10, cellheight - 5, blue) + when tile_server_bottom then + fill_rect(x + 5, y, cellwidth - 10, cellheight - 5, blue) + when tile_terminal then + fill_rect(x + 8, y + 8, 16, 16, c2) + else + end + + end + end + + ext_fill_rect(x, y, w, h : INTEGER; c : INTEGER) is + external "C" + end + + wrap_flag : BOOLEAN + + open_list : LINKED_LIST[TILE] + + rand : STD_RAND + + generate_board is + local + i : INTEGER + t : TILE + do + --place server + !!server_bottom.make_server_bottom + place_tile(server_bottom, servertopi, servertopj + 1) + !!server_top.make_server_top + place_tile(server_top, servertopi, servertopj) + + --generate maze + !!open_list.make + open_list.add_last(server_top) + open_list.add_last(server_bottom) + + from + until open_list.is_empty + loop + rand.next + i := rand.last_integer(open_list.count) + t := open_list @ i + rand.next + i := rand.last_integer(4) + try_extend(t, i) + end + end + + best : INTEGER + + scramble_board is + local + i, j : INTEGER + do + best := 0 + from i := 1 + until i > width + loop + from j := 1 + until j > height + loop + if board.item(i, j) /= server_top then + rand.next + inspect rand.last_integer(4) + when 1 then + rotateccw(i, j) + best := best + 1 + when 2 then + rotatecw(i, j) + best := best + 1 + when 3 then + rotatecw(i, j) + rotatecw(i, j) + best := best + 2 + else + end + end + j := j + 1 + end + i := i + 1 + end + end + + try_extend(t : TILE; dir : INTEGER) is + local + x, y : INTEGER + x1, y1 : INTEGER + t2 : TILE + i : INTEGER + do + if dir = dir_up then + y1 := -1 + elseif dir = dir_down then + y1 := 1 + end + + if dir = dir_left then + x1 := -1 + elseif dir = dir_right then + x1 := 1 + end + + x := maybe_wrapx(t.x + x1) + y := maybe_wrapy(t.y + y1) + + if on_board(x, y) then + t2 := board.item(x, y) + if t = server_top and then (dir = dir_left or else dir = dir_right) then + elseif t2 /= Void then + else + !!t2.make + place_tile(t2, x, y) + t.neighbour.put(True, dir) + t2.neighbour.put(True, dir_opposite(dir)) + open_list.add_last(t2) + + from i := open_list.lower + until i > open_list.upper + loop + if is_surrounded(open_list @ i) then + open_list.remove(i) + else + i := i + 1 + end + end + end + end + end + + is_surrounded(t : TILE) : BOOLEAN is + local + dir : INTEGER + x, y : INTEGER + x1, y1 : INTEGER + count : INTEGER + do + Result := True + from dir := 1 + until dir > 4 + loop + if t.neighbour.item(dir) then + count := count + 1 + end + y1 := 0 + if dir = dir_up then + y1 := -1 + elseif dir = dir_down then + y1 := 1 + end + + x1 := 0 + if dir = dir_left then + x1 := -1 + elseif dir = dir_right then + x1 := 1 + end + + x := maybe_wrapx(t.x + x1) + y := maybe_wrapy(t.y + y1) + + if on_board(x, y) then + if board.item(x, y) = Void then + if t = server_top then + if dir /= dir_left and then dir /= dir_right then + Result := False + end + else + Result := False + end + end + end + dir := dir + 1 + end + if count >= 3 then + Result := True + end + end + + place_tile(tile : TILE; x, y : INTEGER) is + do + tile.put_xy(x, y) + board.put(tile, x, y) + end + + poll_event : EVENT is + local + em : EVENTMAKER + do + Result := ext_poll_event(em) + end + + ext_init is + external "C" + end + + ext_poll_event(em : EVENTMAKER) : EVENT is + external "C" alias "ext_poll_event" + end + + ext_update_screen is + external "C" + end + + fill_rect(x, y, w, h : INTEGER; c : COLOR) is + do + --ext_fill_rect(x + offsetx, y + offsety, w, h, c.to_integer) + ext_fill_rect(x, y, w, h, c.to_integer) + end + + blank_screen is + do + fill_rect(0, 0, 640, 480, black) + end +end diff --git a/sdl_constant.e b/sdl_constant.e new file mode 100644 index 0000000..7c0fb67 --- /dev/null +++ b/sdl_constant.e @@ -0,0 +1,301 @@ +deferred class SDL_CONSTANT +feature + sdlk_unknown : INTEGER is 0 + sdlk_first : INTEGER is 0 + sdlk_backspace : INTEGER is 8 + sdlk_tab : INTEGER is 9 + sdlk_clear : INTEGER is 12 + sdlk_return : INTEGER is 13 + sdlk_pause : INTEGER is 19 + sdlk_escape : INTEGER is 27 + sdlk_space : INTEGER is 32 + sdlk_exclaim : INTEGER is 33 + sdlk_quotedbl : INTEGER is 34 + sdlk_hash : INTEGER is 35 + sdlk_dollar : INTEGER is 36 + sdlk_ampersand : INTEGER is 38 + sdlk_quote : INTEGER is 39 + sdlk_leftparen : INTEGER is 40 + sdlk_rightparen : INTEGER is 41 + sdlk_asterisk : INTEGER is 42 + sdlk_plus : INTEGER is 43 + sdlk_comma : INTEGER is 44 + sdlk_minus : INTEGER is 45 + sdlk_period : INTEGER is 46 + sdlk_slash : INTEGER is 47 + sdlk_0 : INTEGER is 48 + sdlk_1 : INTEGER is 49 + sdlk_2 : INTEGER is 50 + sdlk_3 : INTEGER is 51 + sdlk_4 : INTEGER is 52 + sdlk_5 : INTEGER is 53 + sdlk_6 : INTEGER is 54 + sdlk_7 : INTEGER is 55 + sdlk_8 : INTEGER is 56 + sdlk_9 : INTEGER is 57 + sdlk_colon : INTEGER is 58 + sdlk_semicolon : INTEGER is 59 + sdlk_less : INTEGER is 60 + sdlk_equals : INTEGER is 61 + sdlk_greater : INTEGER is 62 + sdlk_question : INTEGER is 63 + sdlk_at : INTEGER is 64 + sdlk_leftbracket : INTEGER is 91 + sdlk_backslash : INTEGER is 92 + sdlk_rightbracket : INTEGER is 93 + sdlk_caret : INTEGER is 94 + sdlk_underscore : INTEGER is 95 + sdlk_backquote : INTEGER is 96 + sdlk_a : INTEGER is 97 + sdlk_b : INTEGER is 98 + sdlk_c : INTEGER is 99 + sdlk_d : INTEGER is 100 + sdlk_e : INTEGER is 101 + sdlk_f : INTEGER is 102 + sdlk_g : INTEGER is 103 + sdlk_h : INTEGER is 104 + sdlk_i : INTEGER is 105 + sdlk_j : INTEGER is 106 + sdlk_k : INTEGER is 107 + sdlk_l : INTEGER is 108 + sdlk_m : INTEGER is 109 + sdlk_n : INTEGER is 110 + sdlk_o : INTEGER is 111 + sdlk_p : INTEGER is 112 + sdlk_q : INTEGER is 113 + sdlk_r : INTEGER is 114 + sdlk_s : INTEGER is 115 + sdlk_t : INTEGER is 116 + sdlk_u : INTEGER is 117 + sdlk_v : INTEGER is 118 + sdlk_w : INTEGER is 119 + sdlk_x : INTEGER is 120 + sdlk_y : INTEGER is 121 + sdlk_z : INTEGER is 122 + sdlk_delete : INTEGER is 127 + + + + sdlk_world_0 : INTEGER is 160 + sdlk_world_1 : INTEGER is 161 + sdlk_world_2 : INTEGER is 162 + sdlk_world_3 : INTEGER is 163 + sdlk_world_4 : INTEGER is 164 + sdlk_world_5 : INTEGER is 165 + sdlk_world_6 : INTEGER is 166 + sdlk_world_7 : INTEGER is 167 + sdlk_world_8 : INTEGER is 168 + sdlk_world_9 : INTEGER is 169 + sdlk_world_10 : INTEGER is 170 + sdlk_world_11 : INTEGER is 171 + sdlk_world_12 : INTEGER is 172 + sdlk_world_13 : INTEGER is 173 + sdlk_world_14 : INTEGER is 174 + sdlk_world_15 : INTEGER is 175 + sdlk_world_16 : INTEGER is 176 + sdlk_world_17 : INTEGER is 177 + sdlk_world_18 : INTEGER is 178 + sdlk_world_19 : INTEGER is 179 + sdlk_world_20 : INTEGER is 180 + sdlk_world_21 : INTEGER is 181 + sdlk_world_22 : INTEGER is 182 + sdlk_world_23 : INTEGER is 183 + sdlk_world_24 : INTEGER is 184 + sdlk_world_25 : INTEGER is 185 + sdlk_world_26 : INTEGER is 186 + sdlk_world_27 : INTEGER is 187 + sdlk_world_28 : INTEGER is 188 + sdlk_world_29 : INTEGER is 189 + sdlk_world_30 : INTEGER is 190 + sdlk_world_31 : INTEGER is 191 + sdlk_world_32 : INTEGER is 192 + sdlk_world_33 : INTEGER is 193 + sdlk_world_34 : INTEGER is 194 + sdlk_world_35 : INTEGER is 195 + sdlk_world_36 : INTEGER is 196 + sdlk_world_37 : INTEGER is 197 + sdlk_world_38 : INTEGER is 198 + sdlk_world_39 : INTEGER is 199 + sdlk_world_40 : INTEGER is 200 + sdlk_world_41 : INTEGER is 201 + sdlk_world_42 : INTEGER is 202 + sdlk_world_43 : INTEGER is 203 + sdlk_world_44 : INTEGER is 204 + sdlk_world_45 : INTEGER is 205 + sdlk_world_46 : INTEGER is 206 + sdlk_world_47 : INTEGER is 207 + sdlk_world_48 : INTEGER is 208 + sdlk_world_49 : INTEGER is 209 + sdlk_world_50 : INTEGER is 210 + sdlk_world_51 : INTEGER is 211 + sdlk_world_52 : INTEGER is 212 + sdlk_world_53 : INTEGER is 213 + sdlk_world_54 : INTEGER is 214 + sdlk_world_55 : INTEGER is 215 + sdlk_world_56 : INTEGER is 216 + sdlk_world_57 : INTEGER is 217 + sdlk_world_58 : INTEGER is 218 + sdlk_world_59 : INTEGER is 219 + sdlk_world_60 : INTEGER is 220 + sdlk_world_61 : INTEGER is 221 + sdlk_world_62 : INTEGER is 222 + sdlk_world_63 : INTEGER is 223 + sdlk_world_64 : INTEGER is 224 + sdlk_world_65 : INTEGER is 225 + sdlk_world_66 : INTEGER is 226 + sdlk_world_67 : INTEGER is 227 + sdlk_world_68 : INTEGER is 228 + sdlk_world_69 : INTEGER is 229 + sdlk_world_70 : INTEGER is 230 + sdlk_world_71 : INTEGER is 231 + sdlk_world_72 : INTEGER is 232 + sdlk_world_73 : INTEGER is 233 + sdlk_world_74 : INTEGER is 234 + sdlk_world_75 : INTEGER is 235 + sdlk_world_76 : INTEGER is 236 + sdlk_world_77 : INTEGER is 237 + sdlk_world_78 : INTEGER is 238 + sdlk_world_79 : INTEGER is 239 + sdlk_world_80 : INTEGER is 240 + sdlk_world_81 : INTEGER is 241 + sdlk_world_82 : INTEGER is 242 + sdlk_world_83 : INTEGER is 243 + sdlk_world_84 : INTEGER is 244 + sdlk_world_85 : INTEGER is 245 + sdlk_world_86 : INTEGER is 246 + sdlk_world_87 : INTEGER is 247 + sdlk_world_88 : INTEGER is 248 + sdlk_world_89 : INTEGER is 249 + sdlk_world_90 : INTEGER is 250 + sdlk_world_91 : INTEGER is 251 + sdlk_world_92 : INTEGER is 252 + sdlk_world_93 : INTEGER is 253 + sdlk_world_94 : INTEGER is 254 + sdlk_world_95 : INTEGER is 255 + + + sdlk_kp0 : INTEGER is 256 + sdlk_kp1 : INTEGER is 257 + sdlk_kp2 : INTEGER is 258 + sdlk_kp3 : INTEGER is 259 + sdlk_kp4 : INTEGER is 260 + sdlk_kp5 : INTEGER is 261 + sdlk_kp6 : INTEGER is 262 + sdlk_kp7 : INTEGER is 263 + sdlk_kp8 : INTEGER is 264 + sdlk_kp9 : INTEGER is 265 + sdlk_kp_period : INTEGER is 266 + sdlk_kp_divide : INTEGER is 267 + sdlk_kp_multiply : INTEGER is 268 + sdlk_kp_minus : INTEGER is 269 + sdlk_kp_plus : INTEGER is 270 + sdlk_kp_enter : INTEGER is 271 + sdlk_kp_equals : INTEGER is 272 + + + sdlk_up : INTEGER is 273 + sdlk_down : INTEGER is 274 + sdlk_right : INTEGER is 275 + sdlk_left : INTEGER is 276 + sdlk_insert : INTEGER is 277 + sdlk_home : INTEGER is 278 + sdlk_end : INTEGER is 279 + sdlk_pageup : INTEGER is 280 + sdlk_pagedown : INTEGER is 281 + + + sdlk_f1 : INTEGER is 282 + sdlk_f2 : INTEGER is 283 + sdlk_f3 : INTEGER is 284 + sdlk_f4 : INTEGER is 285 + sdlk_f5 : INTEGER is 286 + sdlk_f6 : INTEGER is 287 + sdlk_f7 : INTEGER is 288 + sdlk_f8 : INTEGER is 289 + sdlk_f9 : INTEGER is 290 + sdlk_f10 : INTEGER is 291 + sdlk_f11 : INTEGER is 292 + sdlk_f12 : INTEGER is 293 + sdlk_f13 : INTEGER is 294 + sdlk_f14 : INTEGER is 295 + sdlk_f15 : INTEGER is 296 + + + sdlk_numlock : INTEGER is 300 + sdlk_capslock : INTEGER is 301 + sdlk_scrollock : INTEGER is 302 + sdlk_rshift : INTEGER is 303 + sdlk_lshift : INTEGER is 304 + sdlk_rctrl : INTEGER is 305 + sdlk_lctrl : INTEGER is 306 + sdlk_ralt : INTEGER is 307 + sdlk_lalt : INTEGER is 308 + sdlk_rmeta : INTEGER is 309 + sdlk_lmeta : INTEGER is 310 + sdlk_lsuper : INTEGER is 311 + sdlk_rsuper : INTEGER is 312 + sdlk_mode : INTEGER is 313 + + + sdlk_help : INTEGER is 315 + sdlk_print : INTEGER is 316 + sdlk_sysreq : INTEGER is 317 + sdlk_break : INTEGER is 318 + sdlk_menu : INTEGER is 319 + sdlk_power : INTEGER is 320 + sdlk_euro : INTEGER is 321 + sdlk_last : INTEGER is 322 + + kmod_none : INTEGER is 0 --0x0000 + kmod_lshift: INTEGER is 1 --0x0001 + kmod_rshift: INTEGER is 2 --0x0002 + kmod_lctrl : INTEGER is 64 --0x0040 + kmod_rctrl : INTEGER is 128 --0x0080 + kmod_lalt : INTEGER is 256 --0x0100 + kmod_ralt : INTEGER is 512 --0x0200 + kmod_lmeta : INTEGER is 1024 --0x0400 + kmod_rmeta : INTEGER is 2048 --0x0800 + kmod_num : INTEGER is 4096 --0x1000 + kmod_caps : INTEGER is 8192 --0x2000 + kmod_mode : INTEGER is 16384 --0x4000 + --KMOD_RESERVED : INTEGER is 0x8000 + + kmod_ctrl : INTEGER is 192 --0x00C0 + --kmod_lctrl|kmod_rctrl + kmod_shift : INTEGER is 3 --0x0003 + --kmod_lshift|kmod_rshift + kmod_alt : INTEGER is 768 --0x0300 + --kmod_lalt|kmod_ralt + --kmod_meta : INTEGER is 0x0C00 + + is_kmod(mod, k : INTEGER) : BOOLEAN is + external "C" + end + + audio_u8 : INTEGER is 8 + audio_s8 : INTEGER is 32776 + audio_s16lsb : INTEGER is 32784 + audio_s16 : INTEGER is 32784 +--#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */ +--#define AUDIO_S8 0x8008 /* Signed 8-bit samples */ +--#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */ +--#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */ +--#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */ +--#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */ +--#define AUDIO_U16 AUDIO_U16LSB +--#define AUDIO_S16 AUDIO_S16LSB + + ttf_style_normal : INTEGER is 0 + ttf_style_bold : INTEGER is 1 + ttf_style_italic : INTEGER is 2 + ttf_style_underline : INTEGER is 4 + + sdl_noevent : INTEGER is 0 + sdl_activeevent : INTEGER is 1 + sdl_keydown : INTEGER is 2 + sdl_keyup : INTEGER is 3 + sdl_mousemotion : INTEGER is 4 + sdl_mousebuttondown : INTEGER is 5 + sdl_mousebuttonup : INTEGER is 6 + bl_network : INTEGER is 33 +end diff --git a/tile.e b/tile.e new file mode 100644 index 0000000..b17cf3b --- /dev/null +++ b/tile.e @@ -0,0 +1,72 @@ +class TILE +inherit DIR_CONSTANT +creation make, make_server_bottom, make_server_top +feature + tile_server_top : INTEGER is 1 + tile_server_bottom : INTEGER is 2 + tile_normal : INTEGER is 3 + tile_terminal : INTEGER is 4 + + type : INTEGER + + neighbour : ARRAY[BOOLEAN] + + x, y : INTEGER + + put_xy(new_x, new_y : INTEGER) is + do + x := new_x + y := new_y + end + + is_connected : BOOLEAN + + connect is + do + is_connected := True + end + + disconnect is + do + is_connected := False + end + + neighbour_count : INTEGER + + count_neighbours is + local + dir : INTEGER + do + from dir := 1 + until dir > 4 + loop + if neighbour.item(dir) then + neighbour_count := neighbour_count + 1 + end + dir := dir + 1 + end + + if neighbour_count = 1 and then + type = tile_normal then + type := tile_terminal + end + end + + make is + do + type := tile_normal + !!neighbour.make(1, 4) + end + + make_server_bottom is + do + type := tile_server_bottom + !!neighbour.make(1, 4) + end + + make_server_top is + do + type := tile_server_top + !!neighbour.make(1, 4) + end +end diff --git a/ttf_font.e b/ttf_font.e new file mode 100644 index 0000000..a3646c1 --- /dev/null +++ b/ttf_font.e @@ -0,0 +1,54 @@ +class TTF_FONT +creation make, load +feature + is_connected : BOOLEAN + + make is + do + end + + load(filename : STRING; size : INTEGER) is + require + filename /= Void + do + ptr := ext_ttf_openfont(filename.to_external, size) + if ptr.is_not_null then + is_connected := True + else + io.put_string("Failed to load font: " + filename + "%N") + end + end + + free is + do + if ptr.is_not_null then + ptr := free_ttf_font(ptr) + is_connected := False + end + end + + set_style(i : INTEGER) is + do + ttf_setfontstyle(ptr, i) + end + + to_external : POINTER is + do + Result := ptr + end + + ttf_setfontstyle(p : POINTER; i : INTEGER) is + external "C" alias "TTF_SetFontStyle" + end + + free_ttf_font(font : POINTER) : POINTER is + external "C" + end + +feature {NONE} + ptr : POINTER + + ext_ttf_openfont(p : POINTER; size : INTEGER) : POINTER is + external "C" + end +end diff --git a/version.h b/version.h new file mode 100644 index 0000000..c718acc --- /dev/null +++ b/version.h @@ -0,0 +1,21 @@ +/* Holds the version number + * Ben Lynn + */ +/* +Copyright (C) 2002 Benjamin Lynn (blynn@cs.stanford.edu) + +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 2 +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#define NETWALK_VERSION "netwalk-0.1" diff --git a/win32.config b/win32.config new file mode 100644 index 0000000..368e237 --- /dev/null +++ b/win32.config @@ -0,0 +1,2 @@ +main_font C:\WINDOWS\Fonts\Arial.ttf +big_font C:\WINDOWS\Fonts\Impact.ttf -- 2.11.4.GIT