1% use.pl
    2% Dec 13, 2035
    3% Douglas Miles
    4%
    5% This file defines the basic use (pick up) predicate
    6%
    7
    8% :-swi_module(user). 
    9:-swi_module(moduleUse, [do_act_use/3]).   10
   11:- include(prologmud(mud_header)).   12
   13% :- register_module_type(mtCommand).
   14
   15meta_argtypes(action_verb_useable(vtVerb,tCol,ftTerm(tPred),ftTerm(tPred),ftTerm(tPred))).
   16
   17:- install_constant_renamer_until_eof.   18:- set_prolog_flag(do_renames_sumo,never).   19
   20==>genls(isEach('PortableObject','ProtectiveAttire',tStowAble),tWieldAble).
   21genls('FluidReservoir',tDrinkAble).
   22genls(tWeapon,tWieldAble).
   23genls(tContolDevice,tUseAble).
   24genls(tWieldAble,tUseAble).
   25genls(tCarryAble,tStowAble).
   26
   27
   28% incase someone forgets to "include"
   29prologHybrid(genlPreds/2).
   30prologHybrid(genlInverse/2).
   31prologHybrid(mudPossess/2).
   32
   33
   34
   35
   36% Spatial Prepositionals relating the Object to a Location
   37ttRelationType(locObjBasePred).
   38locObjBasePred(P)==>(prologHybrid(P),rtBinaryPredicate(P)).
   39locObjBasePred(P),genlInverse(P,Inverse) ==> locBaseObjPred(Inverse).
   40locObjBasePred(localityOfObject).
   41locObjBasePred(inRegion).
   42
   43singleValuedInArg(inRegion,2).
   44
   45% Spatial Prepositionals relating the Location to an Object:
   46ttRelationType(locBaseObjPred).
   47locBaseObjPred(P)==>(prologHybrid(P),rtBinaryPredicate(P)).
   48locBaseObjPred(P),genlInverse(P,Inverse) ==> locObjBasePred(Inverse).
   49locBaseObjPred(mudContains).
   50
   51% Spatial Prepositionals relating the Location to an Object AND "has" possession
   52ttRelationType(locBaseObjPredHas).
   53locBaseObjPredHas(P)==>locBaseObjPred(P).
   54locBaseObjPredHas(P)==> 
   55  (genlPreds(P,mudPossess), 
   56  (t(P,A,O) ==> mudPossess(A,O))).
   57locBaseObjPredHas(mudWielding).
   58locBaseObjPredHas(mudStowing).
   59locBaseObjPredHas(wearsClothing).
   60
   61
   62% Transitive: locatedAtPrep/3
   63prologMultiValued(locatedAtPrep(tSpatialThing,tSpatialThing,rtBinaryPredicate)).
   64
   65(locatedAtPrep(Obj,Whom,A),locatedAtPrep(Whom,Where,B))
   66   ==> locatedAtPrep(Obj,Where,spatialPrepJoinFn(A,B)).
   67
   68locObjBasePred(P) ==> 
   69  (t(P,Obj,Base) <==> locatedAtPrep(Obj,Base,P)).
   70
   71locBaseObjPred(P) ==> 
   72  (t(P,Base,Obj) <==> locatedAtPrep(Obj,Base,P)).
   73
   74%?-   mpred_why((prologMultiValued(wearsClothing))).
   75
   76prologMultiValued(wearsClothing(tAgent,tWearAble)).
   77prologMultiValued(mudWielding(tAgent,tWieldAble)).
   78prologMultiValued(mudStowing(tAgent,tStowAble)).
   79prologMultiValued(mudContains(tContainer,tObj)).
   80
   81% "possessing knowledge" mudKnowing is a type of mudPossess but not spatial
   82prologHybrid(mudKnowing(tAgent,ftTerm)).
   83genlPreds(mudKnowing,mudPossess).
   84
   85% genlPreds(mudPossess,mudContains).
   86genlInverse(mudContains,mudInsideOf).
   87%genlInverse(mudStowing,mudInsideOf).
   88%genlInverse(mudInsideOf,mudPossess).
   89
   90
   91prologHybrid(action_verb_useable/5).
 action_verb_useable(Action, RequiredArg, AddedProp, PrecondProp, RemovedProp) is nondet
   94action_verb_useable(actWear,tWearAble,wearsClothing,mudPossess,mudStowing).
   95action_verb_useable(actWield,tWieldAble,mudWielding,mudPossess,mudStowing).
   96action_verb_useable(actStow,tStowAble,mudStowing,mudPossess,mudWielding).
   97% action_verb_useable(actUse,mudUsing,tUseAble,mudPossess,mudPossess).
   98
   99:- baseKB:import(logicmoo_util_strings:convert_to_cycString/2).  100
  101
  102==>(action_info(Syntax,String):-
  103 no_repeats([Syntax],(
  104  call_u(action_verb_useable(ActUse,Wieldable,NowWielding,Possessing,Unstowed)),
  105  Syntax=..[ActUse,isAnd([tNearestReachableItem,call(Possessing,isSelfAgent,isThis),Wieldable])])),
  106   must_maplist(name_text_now,[ActUse,Wieldable,Possessing,NowWielding,Unstowed],List),
  107   sformat(String,'~w a ~w that you ~w so it will be ~w and not be ~w afterwards.',List)).
  108
  109agent_call_command(Agent,Syntax) :- 
  110    call_u((action_verb_useable(ActUse,_Wieldable,_NowWielding,_Possessing,_Unstowed),Syntax=..[ActUse,Obj])),
  111    agent_call_command_use(Agent,ActUse,Obj),!.
  112
  113 
  114% Successfully use something
  115agent_call_command_use(Agent,ActUse,Obj) :- 
  116  must_det_l([
  117	once((nearest_reachable_object(Agent,Obj))),
  118	nop((ignore(props(Obj,mudWeight<2)),
  119	ignore(do_act_affect(Agent,ActUse,Obj)))),
  120	do_act_use(ActUse,Agent,Obj),
  121	call_update_charge(Agent,ActUse)]).
  122
  123% Unsuccessfully use something
  124agent_call_command_use(Agent,ActUse,_Obj) :- 
  125	call_update_charge(Agent,ActUse),
  126	add_cmdfailure(Agent,ActUse).
  127
  128get_use_perminance(Obj,ActUse,TakeableType):-
  129 ignore(props(Obj,mudPermanence(ActUse,TakeableType))), 
  130 ignore(TakeableType=vTakenMoves).
  131
  132do_act_use(ActUse,Agent,Obj) :-
  133   must_det_l([  
  134        get_use_perminance(Obj,ActUse,TakeableType),
  135	do_change_use(ActUse,Agent,Obj,TakeableType)]),!.
  136
  137
  138get_add_remove_use(ActUse,Agent,NowWielding,Obj,Unstowed):-     
  139 must_det_l([
  140     action_verb_useable(ActUse,Wieldable,NowWielding,Possessing,Unstowed),
  141      show_failure(isa(Obj,Wieldable)),
  142  %   show_failure(ireq(t(Unstowed,Agent,Obj))),
  143  %   show_failure(not(ireq(t(NowWielding,Agent,Obj)))),
  144     show_failure(ireq(t(Possessing,Agent,Obj)))]).
  145
  146% Is the obect going to stick around after use-ing, either as is or in the agent's possession.
  147do_change_use(ActUse,Agent,Obj,vTakenDeletes):-
  148        get_add_remove_use(ActUse,Agent,NowWielding,Obj,Unstowed),
  149        detatch_object(Obj),
  150        clr(t(Unstowed,Agent,Obj)),
  151        ain(t(NowWielding,Agent,Obj)),    
  152        must_post_use(ActUse,Agent,Obj),
  153        detatch_object(Obj).
  154do_change_use(ActUse,Agent,_Source,vTakenCopyFn(What)) :-
  155        get_add_remove_use(ActUse,Agent,NowWielding,Obj,Unstowed),
  156        create_new_object([What],Obj),
  157        detatch_object(Obj),
  158        clr(t(Unstowed,Agent,Obj)),
  159        ain(t(NowWielding,Agent,Obj)),        
  160        must_post_use(ActUse,Agent,Obj).
  161do_change_use(ActUse,Agent,Obj,vTakenStays) :-        
  162        get_add_remove_use(ActUse,Agent,NowWielding,Obj,Unstowed),
  163        mudAtLoc(Obj,Was),
  164        detatch_object(Obj),
  165        clr(t(Unstowed,Agent,Obj)),
  166        ain(t(NowWielding,Agent,Obj)),
  167        must_post_use(ActUse,Agent,Obj),
  168        detatch_object(Obj),
  169        ain(mudAtLoc(Obj,Was)).
  170% default is same as vTakenMoves
  171do_change_use(ActUse,Agent,Obj,vTakenMoves) :-
  172 must_det_l((
  173        get_add_remove_use(ActUse,Agent,NowWielding,Obj,Unstowed),        
  174        detatch_object(Obj),
  175        clr(t(Unstowed,Agent,Obj)),
  176	ain(t(NowWielding,Agent,Obj)),
  177        must_post_use(ActUse,Agent,Obj))).
  178
  179must_post_use(ActUse,Agent,Obj):-
  180      must_det_l((
  181       get_add_remove_use(ActUse,Agent,NowWielding,Obj,Unstowed),
  182       fmt([Agent,ActUse,Obj]),       
  183       REQ = t(NowWielding,Agent,Obj),
  184       CLR = t(Unstowed,Agent,Obj),
  185       (ireq(REQ) -> true; trace_or_throw(ireq(REQ))),
  186       (ireq(CLR) -> trace_or_throw(not(ireq(REQ))); true))),!.
  187
  188% Record keeping
  189update_charge(Agent,_ActWield) :- 
  190        padd(Agent,mudEnergy(+ -2)).
  191
  192:- include(prologmud(mud_footer)).