1 REGISTER_MINIGAME(bd, "Bulldozer");
3 const int BD_TURN_MOVE = 0x0100; // player must move the bulldozer
4 const int BD_TURN_WIN = 0x0200; // victory
5 const int BD_TURN_LOSS = 0x0400; // they did it?!
6 const int BD_TURN_EDIT = 0x0800; // editing mode
7 const int BD_TURN_TYPE = 0x0f00; // turn type mask
9 const int BD_SF_PLAYERMOVES = MINIG_SF_CUSTOM;
12 const int BD_LET_CNT = 20;
13 const int BD_NUM_CNT = 20;
15 const int BD_TILE_SIZE = 20;
17 const int BD_TEAMS = 1;
31 const int BD_TILE_DOZER = 1;
32 const int BD_TILE_TARGET = 2;
33 const int BD_TILE_BOULDER = 3;
34 const int BD_TILE_BRICK1 = 4;
35 const int BD_TILE_BRICK2 = 5;
36 const int BD_TILE_BRICK3 = 6;
37 const int BD_TILE_BRICK4 = 7;
38 const int BD_TILE_BRICK5 = 8;
39 const int BD_TILE_BRICK6 = 9;
40 const int BD_TILE_BRICK7 = 10;
41 const int BD_TILE_BRICK8 = 11;
42 const int BD_TILE_LAST = 11;
44 string autocvar_sv_minigames_bulldozer_startlevel = "level1";
46 // find same game piece given its tile name
47 entity bd_find_piece(entity minig, string tile, bool check_target)
50 while ( ( e = findentity(e,owner,minig) ) )
51 if ( e.classname == "minigame_board_piece" && e.netname == tile && ((check_target) ? e.bd_tiletype == BD_TILE_TARGET : e.bd_tiletype != BD_TILE_TARGET) )
56 // check if the tile name is valid (15x15 grid)
57 bool bd_valid_tile(string tile)
61 int number = minigame_tile_number(tile);
62 int letter = minigame_tile_letter(tile);
63 return 0 <= number && number < BD_NUM_CNT && 0 <= letter && letter < BD_LET_CNT;
66 entity bd_find_dozer(entity minig)
69 while ( ( e = findentity(e,owner,minig) ) )
70 if ( e.classname == "minigame_board_piece" && e.bd_tiletype == BD_TILE_DOZER )
75 void bd_check_winner(entity minig)
77 int total = 0, valid = 0;
79 while ( ( e = findentity(e,owner,minig) ) )
80 if ( e.classname == "minigame_board_piece" && e.bd_tiletype == BD_TILE_TARGET )
83 if(bd_find_piece(minig, e.netname, false).bd_tiletype == BD_TILE_BOULDER)
89 minig.minigame_flags = BD_TURN_WIN;
90 minigame_server_sendflags(minig,MINIG_SF_UPDATE);
94 bool bd_canfill(int ttype)
105 case BD_TILE_BRICK1: return true;
111 bool bd_move_dozer(entity minigame, entity dozer)
113 if(!dozer.bd_dir_x && !dozer.bd_dir_y)
114 return false; // nope!
116 int myx = minigame_tile_letter(dozer.netname);
117 int myy = minigame_tile_number(dozer.netname);
119 myx += dozer.bd_dir_x;
120 myy += dozer.bd_dir_y;
122 string newpos = minigame_tile_buildname(myx, myy);
123 entity hit = bd_find_piece(minigame, newpos, false);
125 if(!bd_valid_tile(newpos))
129 switch(hit.bd_tiletype)
131 case BD_TILE_DOZER: // wtf, but let's do this incase
139 case BD_TILE_BRICK1: return false;
140 case BD_TILE_BOULDER:
143 int tx = minigame_tile_letter(hit.netname);
144 int ty = minigame_tile_number(hit.netname);
146 tx += dozer.bd_dir_x;
147 ty += dozer.bd_dir_y;
149 testpos = minigame_tile_buildname(tx, ty);
150 entity testhit = bd_find_piece(minigame, testpos, false);
152 if(!bd_valid_tile(testpos) || testhit)
155 if(hit.netname) { strunzone(hit.netname); }
156 hit.netname = strzone(testpos);
157 minigame_server_sendflags(hit,MINIG_SF_UPDATE);
162 if(dozer.netname) { strunzone(dozer.netname); }
163 dozer.netname = strzone(newpos);
169 void bd_move(entity minigame, entity player, string dir)
171 if ( minigame.minigame_flags & BD_TURN_MOVE )
174 //if ( bd_valid_tile(pos) )
175 //if ( bd_find_piece(minigame, pos, false) )
177 entity dozer = bd_find_dozer(minigame);
180 LOG_INFO("Dozer wasn't found!\n");
181 return; // should not happen... TODO: end match?
184 int dxs = 0, dys = 0;
185 string thedir = strtolower(dir);
186 if(thedir == "up" || thedir == "u") { dxs = 0; dys = 1; }
187 if(thedir == "down" || thedir == "dn" || thedir == "d") { dxs = 0; dys = -1; }
188 if(thedir == "left" || thedir == "lt" || thedir == "l") { dxs = -1; dys = 0; }
189 if(thedir == "right" || thedir == "rt" || thedir == "r") { dxs = 1; dys = 0; }
191 int dx = bound(-1, dxs, 1);
192 int dy = bound(-1, dys, 1);
198 if(bd_move_dozer(minigame, dozer))
201 bd_check_winner(minigame);
203 minigame_server_sendflags(dozer,MINIG_SF_UPDATE); // update anyway
204 minigame_server_sendflags(player,BD_SF_PLAYERMOVES);
205 minigame_server_sendflags(minigame,MINIG_SF_UPDATE);
211 void bd_editor_place(entity minigame, entity player, string pos, int thetile, string thedir)
213 if ( minigame.minigame_flags & BD_TURN_EDIT )
214 if ( pos && thetile )
216 if ( bd_valid_tile(pos) )
218 entity found_piece = bd_find_piece(minigame, pos, false);
219 entity targ = bd_find_piece(minigame, pos, true);
221 if(found_piece.bd_tiletype == BD_TILE_DOZER && thedir != "")
223 int dxs = 0, dys = 0;
224 string newdir = strtolower(thedir);
225 if(newdir == "up" || newdir == "u") { dxs = 0; dys = 1; }
226 if(newdir == "down" || newdir == "dn" || newdir == "d") { dxs = 0; dys = -1; }
227 if(newdir == "left" || newdir == "lt" || newdir == "l") { dxs = -1; dys = 0; }
228 if(newdir == "right" || newdir == "rt" || newdir == "r") { dxs = 1; dys = 0; }
230 int dx = bound(-1, dxs, 1);
231 int dy = bound(-1, dys, 1);
233 found_piece.bd_dir_x = dx;
234 found_piece.bd_dir_y = dy;
235 found_piece.bd_dir_z = 0;
236 minigame_server_sendflags(found_piece,MINIG_SF_UPDATE); // update anyway
240 entity dozer = bd_find_dozer(minigame);
241 if(dozer && thetile == BD_TILE_DOZER && pos != dozer.netname)
244 if(found_piece || (targ && thetile != BD_TILE_BOULDER))
246 entity piece = bd_find_piece(minigame, pos, false);
247 if(!piece) piece = bd_find_piece(minigame, pos, true);
251 if(piece.netname) { strunzone(piece.netname); }
253 minigame_server_sendflags(minigame,MINIG_SF_UPDATE);
257 entity piece = msle_spawn(minigame,"minigame_board_piece");
259 piece.netname = strzone(pos);
260 piece.bd_tiletype = thetile;
261 piece.bd_dir = '0 -1 0';
262 minigame_server_sendflags(piece,MINIG_SF_UPDATE);
264 minigame_server_sendflags(minigame,MINIG_SF_UPDATE);
269 void bd_do_move(entity minigame, entity player, string dir, string thetile, string thedir)
271 if(minigame.minigame_flags & BD_TURN_MOVE)
272 bd_move(minigame, player, dir);
274 if(minigame.minigame_flags & BD_TURN_EDIT)
275 bd_editor_place(minigame, player, dir, stof(thetile), thedir);
278 void bd_fill_recurse(entity minigame, entity player, int thetype, int letter, int number)
280 string pos = minigame_tile_buildname(letter,number);
281 if(!bd_valid_tile(pos))
283 if(bd_find_piece(minigame, pos, false) || bd_find_piece(minigame, pos, true))
286 bd_editor_place(minigame, player, pos, thetype, "");
288 bd_fill_recurse(minigame, player, thetype, letter - 1, number);
289 bd_fill_recurse(minigame, player, thetype, letter + 1, number);
290 bd_fill_recurse(minigame, player, thetype, letter, number - 1);
291 bd_fill_recurse(minigame, player, thetype, letter, number + 1);
294 void bd_unfill_recurse(entity minigame, entity player, int thetype, int letter, int number)
296 string pos = minigame_tile_buildname(letter,number);
297 if(!bd_valid_tile(pos))
300 entity targ = bd_find_piece(minigame, pos, true);
301 entity piece = bd_find_piece(minigame, pos, false);
303 if(targ && thetype == targ.bd_tiletype)
305 if(targ.netname) { strunzone(targ.netname); }
308 else if(piece && thetype == piece.bd_tiletype)
310 if(piece.netname) { strunzone(piece.netname); }
315 bd_unfill_recurse(minigame, player, thetype, letter - 1, number);
316 bd_unfill_recurse(minigame, player, thetype, letter + 1, number);
317 bd_unfill_recurse(minigame, player, thetype, letter, number - 1);
318 bd_unfill_recurse(minigame, player, thetype, letter, number + 1);
321 void bd_do_fill(entity minigame, entity player, string dir, string thetile)
323 if(minigame.minigame_flags & BD_TURN_EDIT)
325 int thetype = stof(thetile);
327 entity targ = bd_find_piece(minigame, dir, true);
328 entity piece = bd_find_piece(minigame, dir, false);
330 if(!bd_canfill(thetype) || (piece || targ))
334 if(targ) { killtype = targ.bd_tiletype; }
335 if(piece) { killtype = piece.bd_tiletype; }
339 int letter = minigame_tile_letter(dir);
340 int number = minigame_tile_number(dir);
341 bd_unfill_recurse(minigame, player, killtype, letter, number);
347 int letter = minigame_tile_letter(dir);
348 int number = minigame_tile_number(dir);
350 bd_fill_recurse(minigame, player, thetype, letter, number);
354 void bd_reset_moves(entity minigame)
358 for(e = minigame.minigame_players; e; e = e.list_next)
361 while( (e = findentity(e,owner,minigame)) )
362 if ( e.classname == "minigame_player" )
366 minigame_server_sendflags(e,BD_SF_PLAYERMOVES);
370 void bd_load_level(entity minigame);
371 void bd_setup_pieces(entity minigame)
374 while( (e = findentity(e, owner, minigame)) )
375 if(e.classname == "minigame_board_piece")
377 if(e.netname) { strunzone(e.netname); }
381 bd_load_level(minigame);
384 void bd_do_next_match(entity minigame, entity player)
386 minigame.minigame_flags = BD_TURN_MOVE;
387 minigame_server_sendflags(minigame,MINIG_SF_UPDATE);
389 if(minigame.bd_nextlevel && minigame.bd_nextlevel != "")
391 if(minigame.bd_levelname) { strunzone(minigame.bd_levelname); }
392 minigame.bd_levelname = strzone(minigame.bd_nextlevel);
395 bd_setup_pieces(minigame);
397 bd_reset_moves(minigame);
400 void bd_set_next_match(entity minigame, string next)
402 if(minigame.bd_nextlevel) { strunzone(minigame.bd_nextlevel); }
403 minigame.bd_nextlevel = strzone(next);
406 void bd_next_match(entity minigame, entity player, string next)
408 if(minigame.minigame_flags & BD_TURN_WIN)
409 bd_do_next_match(minigame, player);
410 if(minigame.minigame_flags & BD_TURN_EDIT)
411 bd_set_next_match(minigame, next);
414 // request a new match
415 void bd_restart_match(entity minigame, entity player)
417 minigame.minigame_flags = BD_TURN_MOVE;
418 minigame_server_sendflags(minigame,MINIG_SF_UPDATE);
420 bd_setup_pieces(minigame);
422 bd_reset_moves(minigame);
425 void bd_activate_editor(entity minigame, entity player)
428 if(!player.minigame_players.bd_canedit)
430 sprint(player.minigame_players, "You're not allowed to edit levels, sorry!\n");
435 minigame.minigame_flags = BD_TURN_EDIT;
436 minigame_server_sendflags(minigame,MINIG_SF_UPDATE);
438 bd_reset_moves(minigame);
440 bd_setup_pieces(minigame);
443 string bd_save_piece(entity minigame, entity e)
445 string bd_string = "";
447 bd_string = strcat(bd_string, "\"", e.netname, "\" ");
448 bd_string = strcat(bd_string, ftos(e.bd_tiletype), " ");
449 bd_string = strcat(bd_string, sprintf("\"%.9v\"", e.bd_dir));
454 void bd_set_nextlevel(entity minigame, string s)
458 if(minigame.bd_nextlevel) { strunzone(minigame.bd_nextlevel); }
459 minigame.bd_nextlevel = strzone(argv(2));
462 entity bd_load_piece(entity minigame, string s)
464 // separate pieces between the ; symbols
465 string bd_string = s;
467 tokenize_console(bd_string);
469 entity e = msle_spawn(minigame,"minigame_board_piece");
474 e.netname = strzone(argv(argv_num)); ++argv_num;
475 e.bd_tiletype = stof(argv(argv_num)); ++argv_num;
476 e.bd_dir = stov(argv(argv_num)); ++argv_num;
478 minigame_server_sendflags(e,MINIG_SF_ALL);
483 bool bd_save_level(entity minigame)
485 if(minigame.bd_levelname && minigame.bd_levelname != "")
487 int target_count = 0, boulder_count = 0;
488 entity piece = world;
489 while((piece = findentity(piece,owner,minigame)))
490 if(piece.classname == "minigame_board_piece")
491 if(piece.bd_tiletype == BD_TILE_BOULDER)
493 else if(piece.bd_tiletype == BD_TILE_TARGET)
496 if(boulder_count != target_count)
498 LOG_INFO("Not enough targets or boulders, fix your level!\n");
502 // saves all objects to the database file
506 file_name = strcat("minigames/bulldozer/storage_", minigame.bd_levelname, ".txt");
507 file_get = fopen(file_name, FILE_WRITE);
508 fputs(file_get, strcat("// bulldozer storage \"", minigame.bd_levelname, "\" last updated ", strftime(true, "%d-%m-%Y %H:%M:%S"), "\n"));
510 if(minigame.bd_nextlevel && minigame.bd_nextlevel != "" && fexists(strcat("minigames/bulldozer/storage_", minigame.bd_nextlevel, ".txt")))
511 fputs(file_get, strcat("nextlevel = \"", minigame.bd_nextlevel, "\"\n"));
514 while ( ( e = findentity(e,owner,minigame) ) )
515 if ( e.classname == "minigame_board_piece" )
517 // use a line of text for each object, listing all properties
518 fputs(file_get, strcat(bd_save_piece(minigame, e), "\n"));
528 void bd_load_level(entity minigame)
530 // loads all items from the database file
531 string file_read, file_name;
534 file_name = strcat("minigames/bulldozer/storage_", minigame.bd_levelname, ".txt");
535 file_get = fopen(file_name, FILE_READ);
538 LOG_INFO("^3BULLDOZER: ^7could not find storage file ^3", file_name, "^7, no items were loaded\n");
544 file_read = fgets(file_get);
547 if(substring(file_read, 0, 2) == "//")
549 if(substring(file_read, 0, 1) == "#")
551 if(substring(file_read, 0, 9) == "nextlevel")
553 bd_set_nextlevel(minigame, file_read);
558 e = bd_load_piece(minigame, file_read);
564 void bd_close_editor(entity minigame)
566 entity dozer = bd_find_dozer(minigame);
569 LOG_INFO("You need to place a bulldozer on the level to save it!\n");
573 if(bd_save_level(minigame))
575 minigame.minigame_flags = BD_TURN_MOVE;
576 minigame_server_sendflags(minigame,MINIG_SF_UPDATE);
580 LOG_INFO("You need to set the level name!\n");
587 // required function, handle server side events
588 int bd_server_event(entity minigame, string event, ...)
594 if(minigame.bd_levelname) { strunzone(minigame.bd_levelname); }
595 minigame.bd_levelname = strzone(autocvar_sv_minigames_bulldozer_startlevel);
596 bd_setup_pieces(minigame);
597 minigame.minigame_flags = BD_TURN_MOVE;
604 while( (e = findentity(e, owner, minigame)) )
605 if(e.classname == "minigame_board_piece")
607 if(e.netname) { strunzone(e.netname); }
611 if(minigame.bd_nextlevel) { strunzone(minigame.bd_nextlevel); }
612 if(minigame.bd_levelname) { strunzone(minigame.bd_levelname); }
617 int pl_num = minigame_count_players(minigame);
619 if(pl_num >= BD_TEAMS) { return false; }
628 bd_do_move(minigame, ...(0,entity), ((...(1,int)) >= 2 ? argv(1) : string_null), ((...(1,int)) >= 3 ? argv(2) : string_null), ((...(1,int)) >= 4 ? argv(3) : string_null));
631 bd_next_match(minigame,...(0,entity), ((...(1,int) >= 2 ? argv(1) : string_null)));
634 bd_restart_match(minigame,...(0,entity));
637 bd_activate_editor(minigame,...(0,entity));
640 bd_close_editor(minigame);
643 bd_do_fill(minigame, ...(0,entity), ((...(1,int)) >= 2 ? argv(1) : string_null), ((...(1,int)) >= 3 ? argv(2) : string_null));
651 entity sent = ...(0,entity);
653 if ( sent.classname == "minigame_board_piece" && (sf & MINIG_SF_UPDATE) )
655 int letter = minigame_tile_letter(sent.netname);
656 int number = minigame_tile_number(sent.netname);
658 WriteByte(MSG_ENTITY,letter);
659 WriteByte(MSG_ENTITY,number);
661 WriteByte(MSG_ENTITY,sent.bd_tiletype);
663 int dx = sent.bd_dir_x;
664 int dy = sent.bd_dir_y;
667 WriteByte(MSG_ENTITY,dx);
668 WriteByte(MSG_ENTITY,dy);
670 else if(sent.classname == "minigame_player" && (sf & BD_SF_PLAYERMOVES))
671 WriteShort(MSG_ENTITY,sent.bd_moves);
688 vector bd_boardpos; // HUD board position
689 vector bd_boardsize;// HUD board size
691 string bd_get_tile_pic(int tileid)
695 case BD_TILE_BOULDER: return "bd/boulder";
696 case BD_TILE_BRICK1: return "bd/brick1";
697 case BD_TILE_BRICK2: return "bd/brick2";
698 case BD_TILE_BRICK3: return "bd/brick3";
699 case BD_TILE_BRICK4: return "bd/brick4";
700 case BD_TILE_BRICK5: return "bd/brick5";
701 case BD_TILE_BRICK6: return "bd/brick6";
702 case BD_TILE_BRICK7: return "bd/brick7";
703 case BD_TILE_BRICK8: return "bd/brick8";
704 case BD_TILE_TARGET: return "bd/target";
705 case BD_TILE_DOZER: return "bd/dozer";
711 // Required function, draw the game board
712 void bd_hud_board(vector pos, vector mySize)
714 minigame_hud_fitsqare(pos, mySize);
716 bd_boardsize = mySize;
718 minigame_hud_simpleboard(pos,mySize,minigame_texture("bd/board"));
720 vector tile_size = minigame_hud_denormalize_size('1 1 0' / BD_TILE_SIZE,pos,mySize);
724 FOREACH_MINIGAME_ENTITY(e)
726 if(e.classname == "minigame_board_piece")
728 if(e.bd_tiletype == BD_TILE_TARGET)
731 e.bd_enemy = bd_find_piece(active_minigame, e.netname, false);
733 else if(e.bd_tiletype == BD_TILE_BOULDER)
735 e.bd_hide = false; // reset either way
736 e.bd_hide = ((bd_find_piece(active_minigame, e.netname, true)) != world);
740 FOREACH_MINIGAME_ENTITY(e)
742 if ( e.classname == "minigame_board_piece" )
744 if(e.bd_tiletype != BD_TILE_DOZER && !e.bd_hide) // hide boulders
746 tile_pos = minigame_tile_pos(e.netname,BD_NUM_CNT,BD_LET_CNT);
747 tile_pos = minigame_hud_denormalize(tile_pos,pos,mySize);
749 string thepiece = bd_get_tile_pic(e.bd_tiletype);
752 thepiece = "bd/boulder_target";
754 minigame_drawpic_centered( tile_pos,
755 minigame_texture(thepiece),
756 tile_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL );
761 // draw dozers on top, always
762 FOREACH_MINIGAME_ENTITY(e)
764 if ( e.classname == "minigame_board_piece" && e.bd_tiletype == BD_TILE_DOZER )
766 tile_pos = minigame_tile_pos(e.netname,BD_NUM_CNT,BD_LET_CNT);
767 tile_pos = minigame_hud_denormalize(tile_pos,pos,mySize);
769 vector thedir = e.bd_dir;
772 if(thedir_y == -1) { theang = M_PI; }
773 if(thedir_x == 1) { theang = M_PI/2; }
774 if(thedir_x == -1) { theang = M_PI*3/2; }
776 drawrotpic(tile_pos, theang, minigame_texture("bd/dozer"),
777 tile_size, tile_size/2, '1 1 1',
778 panel_fg_alpha, DRAWFLAG_NORMAL );
782 if(active_minigame.minigame_flags & BD_TURN_EDIT)
783 if(bd_valid_tile(bd_curr_pos))
785 entity piece = bd_find_piece(active_minigame, bd_curr_pos, false);
786 entity targ = bd_find_piece(active_minigame, bd_curr_pos, true);
787 string thepiece = ((piece || (targ && bd_curr_tile != BD_TILE_BOULDER)) ? "bd/delete" : bd_get_tile_pic(bd_curr_tile));
789 tile_pos = minigame_tile_pos(bd_curr_pos,BD_LET_CNT,BD_NUM_CNT);
790 tile_pos = minigame_hud_denormalize(tile_pos,pos,mySize);
791 if(bd_curr_tile == BD_TILE_DOZER)
793 drawrotpic(tile_pos, M_PI, minigame_texture("bd/dozer"),
794 tile_size, tile_size/2, '1 1 1',
795 panel_fg_alpha/2, DRAWFLAG_NORMAL );
799 minigame_drawpic_centered( tile_pos,
800 minigame_texture(thepiece),
801 tile_size, '1 1 1', panel_fg_alpha/2, DRAWFLAG_NORMAL );
805 if ( (active_minigame.minigame_flags & BD_TURN_LOSS) || (active_minigame.minigame_flags & BD_TURN_WIN) )
807 vector winfs = hud_fontsize*2;
808 string victory_text = "Game over!";
810 if(active_minigame.minigame_flags & BD_TURN_WIN)
811 victory_text = "Well done! Click 'Next Level' to continue";
813 vector win_pos = pos+eY*(mySize_y-winfs_y)/2;
815 win_sz = minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
816 sprintf("%s", victory_text),
817 winfs, 0, DRAWFLAG_NORMAL, 0.5);
819 drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'0.3 0.3 1',0.8,DRAWFLAG_ADDITIVE);
821 minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
822 sprintf("%s", victory_text),
823 winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
828 // Required function, draw the game status panel
829 void bd_hud_status(vector pos, vector mySize)
833 ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
834 hud_fontsize * 2, '0.25 0.47 0.72', panel_fg_alpha, DRAWFLAG_NORMAL,0.5);
839 vector player_fontsize = hud_fontsize * 1.75;
840 ts_y = ( mySize_y - 2*player_fontsize_y ) / BD_TEAMS;
843 vector tile_size = '48 48 0';
846 drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
847 mypos_y += player_fontsize_y;
848 drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
851 FOREACH_MINIGAME_ENTITY(e)
853 if ( e.classname == "minigame_player" )
856 minigame_drawcolorcodedstring_trunc(mySize_x,mypos,
857 GetPlayerName(e.minigame_playerslot-1),
858 player_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
860 mypos_y += player_fontsize_y;
861 string thepiece = "bd/dozer";
862 if(active_minigame.minigame_flags & BD_TURN_EDIT)
863 thepiece = bd_get_tile_pic(bd_curr_tile);
865 minigame_texture(thepiece),
866 tile_size * 0.7, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL );
868 mypos_x += tile_size_x;
870 drawstring(mypos,ftos(e.bd_moves),tile_size,
871 '0.7 0.84 1', panel_fg_alpha, DRAWFLAG_NORMAL);
876 // Turn a set of flags into a help message
877 string bd_turn_to_string(int turnflags)
879 if ( turnflags & BD_TURN_LOSS )
880 return _("Better luck next time!");
882 if ( turnflags & BD_TURN_WIN )
884 return _("Tubular! Press \"Next Level\" to continue!");
886 return _("Wicked! Press \"Next Level\" to continue!");
888 if( turnflags & BD_TURN_EDIT )
889 return _("Press the space bar to change your currently selected tile");
891 if ( turnflags & BD_TURN_MOVE )
892 return _("Push the boulders onto the targets");
897 // Make the correct move
898 void bd_make_move(entity minigame, string dir)
900 if ( minigame.minigame_flags == BD_TURN_MOVE )
902 minigame_cmd("move ", dir);
906 void bd_editor_make_move(entity minigame, string dir)
908 if ( minigame.minigame_flags == BD_TURN_EDIT )
910 minigame_cmd("move ", bd_curr_pos, " ", ftos(bd_curr_tile), " ", dir);
914 void bd_editor_fill(entity minigame)
916 if ( minigame.minigame_flags == BD_TURN_EDIT )
918 minigame_cmd("fill ", bd_curr_pos, " ", ftos(bd_curr_tile));
922 void bd_set_curr_pos(string s)
925 strunzone(bd_curr_pos);
931 bool bd_normal_move(entity minigame, int themove)
936 case K_KP_RIGHTARROW:
937 bd_make_move(minigame, "r");
941 bd_make_move(minigame, "l");
945 bd_make_move(minigame, "u");
949 bd_make_move(minigame, "d");
956 bool bd_change_dozer_angle(entity minigame)
958 entity dozer = bd_find_piece(minigame, bd_curr_pos, false);
959 if(!dozer || dozer.bd_tiletype != BD_TILE_DOZER)
963 vector dir = dozer.bd_dir;
964 if(dir.x == 0 && dir.y == 0) { thedir = "r"; }
966 if(dir.x == 0 && dir.y == 1) { thedir = "r"; }
967 if(dir.x == 0 && dir.y ==-1) { thedir = "l"; }
968 if(dir.x ==-1 && dir.y == 0) { thedir = "u"; }
969 if(dir.x == 1 && dir.y == 0) { thedir = "d"; }
971 bd_editor_make_move(minigame, thedir);
975 bool bd_editor_move(entity minigame, int themove)
980 case K_KP_RIGHTARROW:
982 bd_set_curr_pos("a3");
984 bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,1,0,BD_NUM_CNT,BD_LET_CNT));
989 bd_set_curr_pos("c3");
991 bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,-1,0,BD_NUM_CNT,BD_LET_CNT));
996 bd_set_curr_pos("a1");
998 bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,0,1,BD_NUM_CNT,BD_LET_CNT));
1001 case K_KP_DOWNARROW:
1002 if ( ! bd_curr_pos )
1003 bd_set_curr_pos("a3");
1005 bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,0,-1,BD_NUM_CNT,BD_LET_CNT));
1009 bd_editor_make_move(minigame, "");
1012 if(bd_change_dozer_angle(minigame))
1015 if(bd_curr_tile > BD_TILE_LAST)
1023 // Required function, handle client events
1024 int bd_client_event(entity minigame, string event, ...)
1030 minigame.message = bd_turn_to_string(minigame.minigame_flags);
1031 bd_set_curr_pos("");
1032 bd_curr_tile = BD_TILE_BRICK1;
1037 if(minigame.minigame_flags & BD_TURN_MOVE)
1039 if(bd_normal_move(minigame, ...(0,int)))
1043 if(minigame.minigame_flags & BD_TURN_EDIT)
1045 if(bd_editor_move(minigame, ...(0,int)))
1051 case "mouse_pressed":
1053 if(minigame.minigame_flags & BD_TURN_EDIT)
1055 if(...(0,int) == K_MOUSE1)
1057 bd_editor_make_move(minigame, "");
1061 if(...(0,int) == K_MOUSE2)
1063 bd_editor_fill(minigame);
1072 if(minigame.minigame_flags & BD_TURN_EDIT)
1074 vector mouse_pos = minigame_hud_normalize(mousepos,bd_boardpos,bd_boardsize);
1075 bd_set_curr_pos(minigame_tile_name(mouse_pos,BD_LET_CNT,BD_NUM_CNT));
1076 if ( ! bd_valid_tile(bd_curr_pos) )
1077 bd_set_curr_pos("");
1081 case "network_receive":
1083 entity sent = ...(0,entity);
1084 int sf = ...(1,int);
1085 if ( sent.classname == "minigame" )
1087 if ( sf & MINIG_SF_UPDATE )
1089 sent.message = bd_turn_to_string(sent.minigame_flags);
1090 //if ( sent.minigame_flags & minigame_self.team )
1094 else if(sent.classname == "minigame_board_piece")
1096 if(sf & MINIG_SF_UPDATE)
1098 int letter = ReadByte();
1099 int number = ReadByte();
1100 if(sent.netname) { strunzone(sent.netname); }
1101 sent.netname = strzone(minigame_tile_buildname(letter, number));
1103 sent.bd_tiletype = ReadByte();
1105 int dx = ReadByte();
1106 int dy = ReadByte();
1108 if(dx == 2) dx = -1;
1109 if(dy == 2) dy = -1;
1116 else if(sent.classname == "minigame_player" && (sf & BD_SF_PLAYERMOVES))
1117 sent.bd_moves = ReadShort(); // make this a byte when possible
1123 HUD_MinigameMenu_CustomEntry(...(0,entity),_("Next Level"),"next");
1124 HUD_MinigameMenu_CustomEntry(...(0,entity),_("Restart"),"restart");
1125 HUD_MinigameMenu_CustomEntry(...(0,entity),_("Editor"),"edit");
1126 HUD_MinigameMenu_CustomEntry(...(0,entity),_("Save"),"save");
1131 if(...(0,string) == "next")
1132 minigame_cmd("next");
1133 if(...(0,string) == "restart")
1134 minigame_cmd("restart");
1135 if(...(0,string) == "edit")
1136 minigame_cmd("edit");
1137 if(...(0,string) == "save")
1138 minigame_cmd("save");