bandit

oldschool thievery roguelike
git clone git://moonbender.net/bandit
Log | Files | Refs | README

bandit_action.c (1490B)


      1 #include "common.h"
      2 
      3 extern u32 ltiles[];
      4 extern u32 tile_flags[];
      5 
      6 u32 target = 0;
      7 
      8 void door(u32 index) {
      9 	u32 * tile = (ltiles + index);
     10 	if (*tile == TILE_DOOR_OPEN) {
     11 		*tile = TILE_DOOR_CLOSED;	
     12 		message_push("You close the door.");
     13 		return;
     14 	}
     15 	if (*tile == TILE_DOOR_OPEN)
     16 	{
     17 		message_push("1. Quick open");
     18 		message_push("2. Turn knob");
     19 		message_push("3. Kick");
     20 	}
     21 }
     22 
     23 void bandit_action_interact(u32 x, u32 y) {
     24 	u32 target_index;
     25     
     26     target_index = tile_index(x, y);
     27 	if (ltiles[target_index] == TILE_DOOR_OPEN) {
     28 		door(target_index);
     29 	}
     30 
     31 	target = target_index;
     32 }
     33 
     34 void bandit_action(u32 choice) {
     35 	if (ltiles[target] == TILE_DOOR_OPEN)  {
     36 		if (choice == 1) {
     37 			if (tile_flags[target] & (DOOR_LOCK_ENGAGED | DOOR_HAS_LOCK)) {
     38 				message_push("It's locked.");
     39 				return;
     40 			}
     41 			ltiles[target] = TILE_DOOR_OPEN;
     42 			message_push("You open the door.");
     43 			return;
     44 		} else if (choice == 2) {
     45 			if (tile_flags[target] & (DOOR_LOCK_ENGAGED | DOOR_HAS_LOCK)) {
     46 				message_push("You twist the doorknob. It's locked.");
     47 			} else if (tile_flags[target] & DOOR_LOCK_ENGAGED && tile_flags[target] ^ DOOR_HAS_LOCK) {
     48 			    message_push("You twist the doorknob. The lock is broken.");
     49             } else {
     50                 message_push("You twist the doorknob. It's unlocked.");
     51             }
     52 			return;
     53 		} else if (choice == 3) {
     54 			message_push("You kick the door open!");
     55 			ltiles[target] = TILE_DOOR_OPEN;
     56 			tile_flags[target] ^= DOOR_HAS_LOCK;
     57 			return;
     58 		}
     59 	}
     60 }